home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / bstfiles.zoo / physics.btx < prev    next >
Lisp/Scheme  |  1992-06-30  |  93KB  |  3,570 lines

  1. % BibTeX styles for various physics journals (27-Feb-1990).
  2. % This file, physics.btx, is based on the file btxbst.doc.
  3.     % Please notify Charles Karney (Karney@Princeton.EDU)
  4.     % of any bugs, improvements, etc.
  5.  
  6. % Run this file through cpp to get specific versions.  I have written
  7. % a version of cpp within Emacs.  To access it put
  8. %    (autoload 'cpp "tex$bibtex:cpp"        ; Use cpp for BibTeX styles
  9. %          "C preprocessor"
  10. %          t)
  11. % into your .emacs file.  Read in this file with
  12. %    emacs tex$bibtex:physics.btx
  13. % and run cpp with e.g.,
  14. %    M-x cpp <ret> aip <ret>
  15. % Save the resulting file to tex$latex:aip.bst.
  16.  
  17. % To accomodate the variations we need (in addition to the definitions below)
  18. %    ATIT_SUPPRESS:    do not include the titles of journal articles
  19. %    NAME_INVERT:    put the initials last
  20. %    NAME_UPPER:    convert names to all caps.
  21. %    MONTH_SUPPRESS:    do not include months in journal articles
  22. %    PAREN_DATE:    dates go in parens in journal articles
  23. %    DATE_FIRST:    dates go before page numbers
  24. %    VOLUME_SPACE:    volume set off with space (not colon)
  25. %    NUM_SUPPRESS:    do not include numbers in journal articles
  26. %    BOLD_VOL:    volume numbers in bold face in journal articles
  27. %    BRACKET_NOTE:    notes in brackets
  28. %    PAGE_START_J:    include only starting page for journal articles
  29. %    PAGE_START_O:    include only starting page for other entries
  30. %    PAGE_ABBREV:    abbreviate page to p. and pages to pp.
  31. %    PHYSICS_JOUR:    include abbreviations for Physics journals
  32. %    COMMA_DELIMIT:    use comma (instead of period) to divide a citation
  33. %    NOTE_SUPPRESS:    suppress the note
  34. %    MAX_NAMES:    max number of authors before using et al (0 = infinity)
  35. %    MIN_NAMES:    number of authors to list with et al.
  36. %    EDIT_VAR:    use "edited by ..." instead of "..., editors"
  37. %    RMP_LABELS:    create RMP-style labels
  38. %    KEY_CITE:    use key as label
  39. %    NAMED_REFS:    use (Smith, 1988) style of citations
  40. %    CSC_NAMES:    names set in caps and small caps
  41. %    JOUR_DEEMPH:    don't emphasize journal name
  42. %    ETAL_EMPH:    emphasize et al.
  43. %    ALT_INCOLL    alternate ordering of fields in incollections
  44.  
  45. % These are all boolean (0 or 1) except for MAX_NAMES and MIN_NAMES.
  46. % These need to satisfy 0 <= MIN_NAMES <= MAX_NAMES.
  47. % The rule here is that if all these are defined to be zero, we revert to
  48. % the standard styles.  For that reason we initialize them all to 0.
  49.  
  50. #   define ATIT_SUPPRESS 0
  51. #   define NAME_INVERT 0
  52. #   define NAME_UPPER 0
  53. #   define MONTH_SUPPRESS 0
  54. #   define PAREN_DATE 0
  55. #   define DATE_FIRST 0
  56. #   define VOLUME_SPACE 0
  57. #   define NUM_SUPPRESS 0
  58. #   define BOLD_VOL 0
  59. #   define BRACKET_NOTE 0
  60. #   define PAGE_START_J 0
  61. #   define PAGE_START_O 0
  62. #   define PAGE_ABBREV 0
  63. #   define PHYSICS_JOUR 0
  64. #   define COMMA_DELIMIT 0
  65. #   define NOTE_SUPPRESS 0
  66. #   define MAX_NAMES 0
  67. #   define MIN_NAMES 0
  68. #   define EDIT_VAR 0
  69. #   define RMP_LABELS 0
  70. #   define KEY_CITE 0
  71. #   define NAMED_REFS 0
  72. #   define CSC_NAMES 0
  73. #   define JOUR_DEEMPH 0
  74. #   define ETAL_EMPH 0
  75. #   define ALT_INCOLL 0
  76.  
  77. % These are the original macros
  78. #   define LAB_ALPH 0
  79. #   define SORTED 0
  80. #   define NAME_FULL 0
  81. #   define ATIT_LOWER 0
  82. #   define MONTH_FULL 0
  83. #   define JOUR_FULL 0
  84.  
  85. #ifdef AIP
  86.     % For American Institute of Physics Journals
  87. #   define ATIT_SUPPRESS 1
  88. #   define PAGE_START_J 1
  89. #   define PHYSICS_JOUR 1
  90. #   define MAX_NAMES 5
  91. #   define MIN_NAMES 1
  92. #   define EDIT_VAR 1
  93. #   define ATIT_LOWER 1
  94. #   define COMMA_DELIMIT 1
  95. #   define VOLUME_SPACE 1
  96. #   define MONTH_SUPPRESS 1
  97. #   define PAREN_DATE 1
  98. #   define NUM_SUPPRESS 1
  99. #   define BOLD_VOL 1
  100. #   define JOUR_DEEMPH 1
  101. #endif
  102.  
  103. #ifdef PF
  104.     % For Physics of Fluids, which now wants ALL the authors
  105.     %  (Same as AIP but infinite names, abbreviate pages, and
  106.     %  alternate incollection)
  107. #   define ATIT_SUPPRESS 1
  108. #   define PAGE_START_J 1
  109. #   define PHYSICS_JOUR 1
  110. #   define EDIT_VAR 1
  111. #   define ATIT_LOWER 1
  112. #   define COMMA_DELIMIT 1
  113. #   define VOLUME_SPACE 1
  114. #   define MONTH_SUPPRESS 1
  115. #   define PAREN_DATE 1
  116. #   define NUM_SUPPRESS 1
  117. #   define BOLD_VOL 1
  118. #   define JOUR_DEEMPH 1
  119. #   define PAGE_ABBREV 1
  120. #   define ALT_INCOLL 1
  121. #endif
  122.  
  123. #ifdef NF
  124.     % For Nuclear Fusion
  125.     % see Nuclear Fusion Vol. 28, No. 2 (1988),
  126.     % "Announcement [of] Guidelines for Bibliographical Citations"
  127. % same as AIP except for NAME_INVERT, NAME_UPPER, DATE_FIRST and 
  128. %  MIN_NAMES and MAX_NAMES set to use only three names if there are 
  129. %  6 or more.  Also, no EDIT_VAR, and use PAGE_START_O and PAGE_ABBREV.
  130. % There are still some nits to be picked (years in parentheses for
  131. % other than journals, volumes having Vol. before them and pages not
  132. % having p.)
  133. #   define ATIT_SUPPRESS 1
  134. #   define PAGE_START_J 1
  135. #   define PAGE_START_O 1
  136. #   define PAGE_ABBREV 1
  137. #   define PHYSICS_JOUR 1
  138. #   define ATIT_LOWER 1
  139. #   define COMMA_DELIMIT 1
  140. #   define VOLUME_SPACE 1
  141. #   define MONTH_SUPPRESS 1
  142. #   define PAREN_DATE 1
  143. #   define NUM_SUPPRESS 1
  144. #   define BOLD_VOL 1
  145. #   define NAME_INVERT 1
  146. #   define NAME_UPPER 1
  147. #   define DATE_FIRST 1
  148. #   define JOUR_DEEMPH 1
  149. #   define MAX_NAMES 5
  150. #   define MIN_NAMES 3
  151. #endif
  152. #ifdef NFLET
  153.     % For Nuclear Fusion Letters
  154. % same as NF except for MIN_NAMES and MAX_NAMES set to 5
  155. #   define ATIT_SUPPRESS 1
  156. #   define PAGE_START_J 1
  157. #   define PAGE_START_O 1
  158. #   define PAGE_ABBREV 1
  159. #   define PHYSICS_JOUR 1
  160. #   define ATIT_LOWER 1
  161. #   define COMMA_DELIMIT 1
  162. #   define VOLUME_SPACE 1
  163. #   define MONTH_SUPPRESS 1
  164. #   define PAREN_DATE 1
  165. #   define NUM_SUPPRESS 1
  166. #   define BOLD_VOL 1
  167. #   define NAME_INVERT 1
  168. #   define NAME_UPPER 1
  169. #   define DATE_FIRST 1
  170. #   define MAX_NAMES 5
  171. #   define MIN_NAMES 5
  172. #   define JOUR_DEEMPH 1
  173. #endif
  174. #ifdef IAEA
  175.     % For IAEA Conferences
  176. % same as NF except for MIN_NAMES and MAX_NAMES set to 1
  177. #   define ATIT_SUPPRESS 1
  178. #   define PAGE_START_J 1
  179. #   define PHYSICS_JOUR 1
  180. #   define EDIT_VAR 1
  181. #   define ATIT_LOWER 1
  182. #   define COMMA_DELIMIT 1
  183. #   define VOLUME_SPACE 1
  184. #   define MONTH_SUPPRESS 1
  185. #   define PAREN_DATE 1
  186. #   define NUM_SUPPRESS 1
  187. #   define BOLD_VOL 1
  188. #   define NAME_INVERT 1
  189. #   define NAME_UPPER 1
  190. #   define DATE_FIRST 1
  191. #   define MAX_NAMES 1
  192. #   define MIN_NAMES 1
  193. #   define JOUR_DEEMPH 1
  194. #endif
  195. #ifdef CPC
  196.     % For Computer Physics Communications
  197. % same as AIP except for NAME_INVERT, DATE_FIRST
  198. #   define ATIT_SUPPRESS 1
  199. #   define PAGE_START_J 1
  200. #   define PHYSICS_JOUR 1
  201. #   define MAX_NAMES 5
  202. #   define MIN_NAMES 1
  203. #   define EDIT_VAR 1
  204. #   define ATIT_LOWER 1
  205. #   define COMMA_DELIMIT 1
  206. #   define VOLUME_SPACE 1
  207. #   define MONTH_SUPPRESS 1
  208. #   define PAREN_DATE 1
  209. #   define NUM_SUPPRESS 1
  210. #   define BOLD_VOL 1
  211. #   define NAME_INVERT 1
  212. #   define DATE_FIRST 1
  213. #   define JOUR_DEEMPH 1
  214. #endif
  215. #ifdef RMP
  216.     % For Reviews of Modern Physics, 
  217. % except first name not inverted yet and order of fields not hacked
  218. #   define LAB_ALPH 1
  219. #   define SORTED 1
  220. #   define RMP_LABELS 1
  221. #   define ATIT_SUPPRESS 1
  222. #   define ATIT_LOWER 1
  223. #   define MONTH_SUPRESS 1
  224. #   define NUM_SUPPRESS 1
  225. #   define VOL_SUPPRESS 1
  226. #   define BOLD_VOL 1
  227. #   define BRACKET_NOTE 1
  228. #   define PAGE_START_J 1
  229. #   define PAGE_START_O 1
  230. #   define PAGE_ABBREV 1
  231. #   define PHYSICS_JOUR 1
  232. #   define COMMA_DELIMIT 1
  233. #   define EDIT_VAR 1
  234. #   define JOUR_DEEMPH 1
  235. #endif
  236. #ifdef REPORT
  237.     % For internal reports
  238. % same as AIP except for ATIT_SUPPRESS, MONTH_SUPPRESS, PAGE_START_J,
  239. % NUM_SUPPRESS, MAX_NAMES, MIN_NAMES
  240. #   define PHYSICS_JOUR 1
  241. #   define EDIT_VAR 1
  242. #   define ATIT_LOWER 0
  243. #   define COMMA_DELIMIT 1
  244. #   define VOLUME_SPACE 1
  245. #   define PAREN_DATE 1
  246. #   define BOLD_VOL 1
  247. #   define JOUR_DEEMPH 1
  248. #endif
  249. #ifdef APALIKE
  250.     % For American Psychological Association
  251.     % (same as ALPHA but with NAMED_REFS set and NAME_FULL unset)
  252. #   define LAB_ALPH 1
  253. #   define SORTED 1
  254. #   define NAME_FULL 0
  255. #   define ATIT_LOWER 1
  256. #   define MONTH_FULL 1
  257. #   define JOUR_FULL 1
  258. #   define NAMED_REFS 1
  259. #   define NAME_INVERT 1
  260. #endif
  261. #ifdef PPCF
  262.     % A physics version of APALIKE
  263. #   define PHYSICS_JOUR 1
  264. #   define LAB_ALPH 1
  265. #   define SORTED 1
  266. #   define NAME_FULL 0
  267. #   define ATIT_LOWER 0
  268. #   define ATIT_SUPPRESS 1
  269. #   define MONTH_FULL 1
  270. #   define JOUR_FULL 0
  271. #   define NAMED_REFS 1
  272. #   define NAME_INVERT 1
  273. #   define ETAL_EMPH 1
  274. #   define CSC_NAMES 1
  275. #   define NUM_SUPPRESS 1
  276. #   define BOLD_VOL 1
  277. #   define VOLUME_SPACE 1
  278. #endif
  279. #ifdef JCP
  280.     % For Journal of Computational Physics
  281.     % Cris Barnes and Dave Mikkelson, 9/25/89
  282. #   define ATIT_SUPPRESS 1
  283. #   define MONTH_SUPPRESS 1
  284. #   define PAREN_DATE 1
  285. #   define VOLUME_SPACE 1
  286. #   define NUM_SUPPRESS 1
  287. #   define BOLD_VOL 1
  288. #   define PAGE_START_J 1
  289. #   define PAGE_START_O 1
  290. #   define PAGE_ABBREV 1
  291. #   define PHYSICS_JOUR 1
  292. #   define COMMA_DELIMIT 1
  293. #   define NOTE_SUPPRESS 1
  294. #   define EDIT_VAR 1
  295. #   define CSC_NAMES 1
  296. #endif
  297. % This is the start of btxbst.doc
  298.  
  299. % BibTeX `plain' family
  300.     % version 0.99b for BibTeX versions 0.99a or later, LaTeX version 2.09.
  301.     % Copyright (C) 1985, all rights reserved.
  302.     % Copying of this file is authorized only if either
  303.     % (1) you make absolutely no changes to your copy, including name, or
  304.     % (2) if you do make changes, you name it something other than
  305.     % btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
  306.     % This restriction helps ensure that all standard styles are identical.
  307.     % The file btxbst.doc has the documentation for this style.
  308. #if NAMED_REFS
  309. % BibTeX `apalike' bibliography style (24-Jan-88 version)
  310. % Adapted from the `alpha' style, version 0.99a; for BibTeX version 0.99a.
  311. % Copyright (C) 1988, all rights reserved.
  312. % Copying of this file is allowed, provided that if you make any changes at all
  313. % you name it something other than `apalike.bst'.
  314. % This restriction helps ensure that all copies are identical.
  315. % Differences between this style and `alpha' are generally heralded by a `%'.
  316. % The file btxbst.doc has the documentation for alpha.bst.
  317. %
  318. % This style should be used with the `apalike' LaTeX style (apalike.sty).
  319. % \cite's come out like "(Jones, 1986)" in the text but there are no labels
  320. % in the bibliography, and something like "(1986)" comes out immediately
  321. % after the author.  Author (and editor) names appear as last name, comma,
  322. % initials.  A `year' field is required for every entry, and so is either
  323. % an author (or in some cases, an editor) field or a key field.
  324. %
  325. % Editorial note:
  326. % Many journals require a style like `apalike', but I strongly, strongly,
  327. % strongly recommend that you not use it if you have a choice---use something
  328. % like `plain' instead.  Mary-Claire van Leunen (A Handbook for Scholars,
  329. % Knopf, 1979) argues convincingly that a style like `plain' encourages better
  330. % writing than one like `apalike'.  Furthermore the strongest arguments for
  331. % using an author-date style like `apalike'---that it's "the most practical"
  332. % (The Chicago Manual of Style, University of Chicago Press, thirteenth
  333. % edition, 1982, pages 400--401)---fall flat on their face with the new
  334. % computer-typesetting technology.  For instance page 401 anachronistically
  335. % states "The chief disadvantage of [a style like `plain'] is that additions
  336. % or deletions cannot be made after the manuscript is typed without changing
  337. % numbers in both text references and list."  LaTeX sidesteps the disadvantage.
  338. %
  339. % History:
  340. %   15-sep-86    (SK,OP)    Original version, by Susan King and Oren Patashnik.
  341. %   10-nov-86    (OP)    Truncated the sort.key$ string to the correct length
  342. %            in bib.sort.order to eliminate error message.
  343. %   24-jan-88    (OP)    Updated for BibTeX version 0.99a, from alpha.bst 0.99a;
  344. %            apalike now sorts by author, then year, then title;
  345. %            THIS `apalike' VERSION DOES NOT WORK WITH BIBTEX 0.98i.
  346. #endif APALIKE
  347. % Please notify Oren Patashnik (PATASHNIK@SCORE.STANFORD.EDU) of any bugs in
  348. % these standard styles or in this documentation file.
  349. %
  350. % This is file btxbxt.doc; it helps document bibliography styles,
  351. % and is also a template file that you can use to make
  352. % several different style files, if you have access to a C preprocessor.
  353. % For example, the standard styles were made by doing something like
  354. %    cpp -P -DPLAIN btxbst.doc plain.txt
  355. %    cpp -P -DUNSRT btxbst.doc unsrt.txt
  356. %    cpp -P -DALPHA btxbst.doc alpha.txt
  357. %    cpp -P -DABBRV btxbst.doc abbrv.txt
  358. % and then renaming after removing unwanted comments and blank lines.
  359. % If you don't have access,
  360. % you can edit this file by hand to imitate the preprocessor,
  361. % with the following explanation of the C preprocessor constructs used here.
  362. %
  363. % The output of the preprocessor is the same as the input, except that certain
  364. % lines will be excluded (and some blank lines will be added).  The sequence
  365. %    #if VAR
  366. %        lines to be included when VAR is not zero
  367. %    #else
  368. %        lines to be included when VAR is zero
  369. %    #endif
  370. % (with the #-signs appearing in column 1) means that one set or the other of
  371. % the lines are to be included depending on the value of VAR.
  372. % The #else part is optional.  Comments can be added after #else and #endif.
  373. % Variables can be set by
  374. %    #define VAR value
  375. % and one can also use #ifdef VAR to see if VAR has any value, and #ifndef
  376. % to see if it has none.
  377. % Another #if form used in this file is #if !VAR, which includes the lines
  378. % after the #if only if VAR is zero.
  379. %
  380. % Convention: Use all uppercase identifiers for these preprocessor variables
  381. % so you can spot them easily
  382. %
  383. % The command line to the preprocessor should define one of PLAIN, UNSRT, ALPHA
  384. % or ABBRV (though PLAIN will be used by default if none is given),
  385. % and the following lines will set various boolean variables to control the
  386. % various lines that are chosen from the rest of the file.
  387. % Each boolean variable should be set true (1) or false (0) in each style.
  388. % Here are the current variables, and their meanings:
  389. %    LAB_ALPH:    an alphabetic label is used (if false then a numeric
  390. %                label is used)
  391. %    SORTED:        the entries should be sorted by label (if nonnumeric)
  392. %                and other info, like authors (if false, then
  393. %                entries remain in order of occurrence)
  394. %    NAME_FULL:    the authors, editors, etc., get the full names as
  395. %                given in the bibliography file (if false, the first
  396. %                names become initials)
  397. %    ATIT_LOWER:    titles of non-"books" (e.g., articles) should be
  398. %                converted to lower-case, except the first letter or
  399. %                first letter after a colon
  400. %                (if false then they appear as in the database)
  401. %    MONTH_FULL:    months are spelled out in full (if false, then
  402. %                they're abbreviated)
  403. %    JOUR_FULL:    macro journal names are spelled out in full
  404. %                (if false then they are abbreviated, currently
  405. %                as they appear in ACM publications)
  406. #ifndef UNSRT
  407. #   ifndef ALPHA
  408. #    ifndef ABBRV
  409. %#        define PLAIN 1
  410. #    endif
  411. #   endif
  412. #endif
  413. #ifdef PLAIN
  414. % plain style (sorted numbers)
  415. #   define LAB_ALPH 0
  416. #   define SORTED 1
  417. #   define NAME_FULL 1
  418. #   define ATIT_LOWER 1
  419. #   define MONTH_FULL 1
  420. #   define JOUR_FULL 1
  421. #endif
  422. #ifdef UNSRT
  423. % unsrt style (unsorted numbers)
  424. #   define LAB_ALPH 0
  425. #   define SORTED 0
  426. #   define NAME_FULL 1
  427. #   define ATIT_LOWER 1
  428. #   define MONTH_FULL 1
  429. #   define JOUR_FULL 1
  430. #endif
  431. #ifdef ALPHA
  432. % alpha style (sorted short alphabetics)
  433. #   define LAB_ALPH 1
  434. #   define SORTED 1
  435. #   define NAME_FULL 1
  436. #   define ATIT_LOWER 1
  437. #   define MONTH_FULL 1
  438. #   define JOUR_FULL 1
  439. #endif
  440. #ifdef ABBRV
  441. % abbrv style (sorted numbers, with abbreviations)
  442. #   define LAB_ALPH 0
  443. #   define SORTED 1
  444. #   define NAME_FULL 0
  445. #   define ATIT_LOWER 1
  446. #   define MONTH_FULL 0
  447. #   define JOUR_FULL 0
  448. #endif
  449. %
  450. %   Entry formatting: Similar to that recommended by Mary-Claire van Leunen
  451. %    in "A Handbook for Scholars".  Book-like titles are italicized
  452. %    (emphasized) and non-book titles are converted to sentence
  453. %    capitilization (and not enclosed in quotes).
  454. %    This file outputs a \newblock between major blocks of an entry
  455. %    (the name \newblock is analogous to the names \newline and \newpage)
  456. %    so that the user can obtain an "open" format, which has a line break
  457. %    before each block and lines after the first are indented within blocks,
  458. %    by giving the optional \documentstyle argument `openbib';
  459. %    The default is the "closed" format---blocks runs together.
  460. %
  461. %   Citation alphabetic label format:
  462. %        [Knu73] for single author (or editor or key)
  463. %        [AHU83] (first letters of last names) for multiple authors
  464. %
  465. %   Citation label numberic format:
  466. %        [number]
  467. %
  468. %   Reference list ordering for sorted, alphabetic lables:
  469. %        alphabetical by citation label, then by author(s) or whatever
  470. %        passes for author in the absence of one, then by year,
  471. %        then title
  472. %
  473. %   Reference list ordering for sorted, numeric lables:
  474. %        alphabetical by author(s) or whatever passes
  475. %        for author in the absence of one, then by year, then title
  476. %
  477. %   Reference list ordering for unsorted:
  478. %        by the order cited in the text
  479. %
  480. %   History
  481. %   12/16/84    (HWT)    Original `plain' version, by Howard Trickey.
  482. %   12/23/84    (LL)    Some comments made by Leslie Lamport.
  483. %    2/16/85    (OP)    Changes based on LL's comments, Oren Patashnik.
  484. %    2/17/85    (HWT)    Template file and other standard styles made.
  485. %    3/28/85    (OP)    First release, version 0.98b for BibTeX 0.98f.
  486. %    5/ 9/85    (OP)    Version 0.98c for BibTeX 0.98i:
  487. %            fixed Theoretical Computer Science macro name;
  488. %            fixed the format.vol.num.pages function.
  489. %    1/24/88    (OP)    Version 0.99a for BibTeX 0.99a, main changes:
  490. %            assignment operator (:=) arguments reversed;
  491. %            the preamble$ function outputs the database PREAMBLE;
  492. %            entry.max$ and global.max$ (built-in) variables replace
  493. %            entry.string.max and global.string.max functions;
  494. %            alphabetizing by year then title, not just title;
  495. %            many unnecessary ties removed; \it ==> \em;
  496. %            the `alpha' style uses a superscripted `+' instead of a
  497. %            `*' for unnamed names in constructing the label;
  498. %            the `abbrv' style now uses "Mar." and "Sept.";
  499. %            the functions calc.label and presort now look at just
  500. %            the fields they're supposed to;
  501. %            BOOKLET, MASTERSTHESIS, TECHREPORT use nonbook titles;
  502. %            INBOOK and INCOLLECTION take an optional type (e.g.
  503. %            type = "Section"), overriding the default "chapter";
  504. %            BOOK, INBOOK, INCOLLECTION, and PROCEEDINGS now allow
  505. %            either volume or number, not just volume;
  506. %            INCOLLECTION now allows an edition and series field;
  507. %            PROCEEDINGS and INPROCEEDINGS now use the address field
  508. %            to tell where a conference was held;
  509. %            INPROCEEDINGS and PROCEEDINGS now allow either volume
  510. %            or number, and also a series field;
  511. %            MASTERSTHESIS and PHDTHESIS accept types other than
  512. %            "Master's thesis" and "PhD thesis";
  513. %            UNPUBLISHED now outputs, in one block, note then date;
  514. %            MANUAL now prints out the organization in
  515. %            the first block if the author field is empty;
  516. %            MISC can't be empty---it requires some optional field.
  517. %    3/23/88    (OP)    Version 0.99b for BibTeX 0.99c---changed the three
  518. %            erroneous occurrences of `cite ' to `cite$ '; this
  519. %            change didn't affect the four standard styles, so the
  520. %            0.99a versions of those styles are still current.
  521. %
  522. % The ENTRY declaration
  523. %   Like Scribe's (according to pages 231-2 of the April '84 edition),
  524. %   but no fullauthor or editors fields because BibTeX does name handling.
  525. %   The annote field is commented out here because this family doesn't
  526. %   include an annotated bibliography style.  And in addition to the fields
  527. %   listed here, BibTeX has a built-in crossref field, explained later.
  528.  
  529. ENTRY
  530. % Fields:
  531.   { address
  532. %        Usually the address of a publisher or other type of organization.
  533. %        Put information in this field only if it helps the reader find the
  534. %        thing---for example you should omit the address of a major
  535. %        publisher entirely.  For a PROCEEDINGS or an INPROCEEDINGS,
  536. %        however, it's the address of the conference; for those two entry
  537. %        types, include the publisher's or organization's address, if
  538. %        necessary, in the publisher or organization field.
  539. %    annote
  540. %        Long annotation---for annotated bibliographies (begins sentence).
  541.     author
  542. %        Name(s) of author(s), in BibTeX name format.
  543.     booktitle
  544. %        Book title when the thing being referenced isn't the whole book.
  545. %        For book entries, the title field should be used instead.
  546.     chapter
  547. %        Chapter (or section or whatever) number.
  548.     edition
  549. %        Edition of a book---should be an ordinal (e.g., "Second").
  550.     editor
  551. %        Name(s) of editor(s), in BibTeX name format.
  552. %        If there is also an author field, then the editor field should be
  553. %        for the book or collection that the work appears in.
  554.     howpublished
  555. %         How something strange has been published (begins sentence).
  556.     institution
  557. %        Sponsoring institution of a technical report.
  558.     journal
  559. %        Journal name (macros are provided for many).
  560.     key
  561. %        Alphabetizing, labeling, and cross-referencing key
  562. %        (needed when an entry has no author or editor).
  563. #if !NAMED_REFS
  564.     month
  565. #else NAMED_REFS
  566. %    month        not used in apalike
  567. #endif
  568. %        Month (macros are provided).
  569.     note
  570. %        To help the reader find a reference (begins sentence).
  571.     number
  572. %        Number of a journal or technical report, or of a work in a series.
  573.     organization
  574. %        Organization sponsoring a conference (or publishing a manual); if
  575. %        the editor (or author) is empty, and if the organization produces
  576. %        an awkward label or cross reference, you should put appropriately
  577. %        condensed organization information in the key field as well.
  578.     pages
  579. %        Page number or numbers (use `--' to separate a range, use `+'
  580. %        to indicate pages following that don't form a simple range).
  581.     publisher
  582. %        Publisher name.
  583.     school
  584. %        School name (for theses).
  585.     series
  586. %        The name of a series or set of books.
  587. %        An individual book will will also have it's own title.
  588.     title
  589. %        The title of the thing you're referred to.
  590.     type
  591. %        Type of a Techreport (e.g., "Research Note") to be used instead of
  592. %        the default "Technical Report"; or, similarly, the type of a
  593. %        thesis; or of a part of a book.
  594.     volume
  595. %        The volume number of a journal or multivolume work.
  596.     year
  597. %        The year should contain only numerals (technically, it should end
  598. %        with four numerals, after purification; doesn't a begin sentence).
  599.   }
  600. % There are no integer entry variables
  601.   {}
  602. % These string entry variables are used to form the citation label.
  603. % In a storage pinch, sort.label can be easily computed on the fly.
  604. #if LAB_ALPH
  605. #if SORTED
  606.   { label extra.label sort.label }
  607. #else !SORTED
  608. % It doesn't seem like a good idea to use an order-of-citation
  609. % reference list when using alphabetic labels, but when this happens
  610. % we do things a little differently
  611.   { label }
  612. #endif SORTED
  613. #else !LAB_ALPH
  614.   { label }
  615. #endif LAB_ALPH
  616.  
  617. % Each entry function starts by calling output.bibitem, to write the
  618. % \bibitem and its arguments to the .BBL file.  Then the various fields
  619. % are formatted and printed by output or output.check.  Those functions
  620. % handle the writing of separators (commas, periods, \newblock's),
  621. % taking care not to do so when they are passed a null string.
  622. % Finally, fin.entry is called to add the final period and finish the
  623. % entry.
  624. %
  625. % A bibliographic reference is formatted into a number of `blocks':
  626. % in the open format, a block begins on a new line and subsequent
  627. % lines of the block are indented.  A block may contain more than
  628. % one sentence (well, not a grammatical sentence, but something to
  629. % be ended with a sentence ending period).  The entry functions should
  630. % call new.block whenever a block other than the first is about to be
  631. % started.  They should call new.sentence whenever a new sentence is
  632. % to be started.  The output functions will ensure that if two
  633. % new.sentence's occur without any non-null string being output between
  634. % them then there won't be two periods output.  Similarly for two
  635. % successive new.block's.
  636. %
  637. % The output routines don't write their argument immediately.
  638. % Instead, by convention, that argument is saved on the stack to be
  639. % output next time (when we'll know what separator needs to come
  640. % after it).  Meanwhile, the output routine has to pop the pending
  641. % output off the stack, append any needed separator, and write it.
  642. %
  643. % To tell which separator is needed, we maintain an output.state.
  644. % It will be one of these values:
  645. %    before.all        just after the \bibitem
  646. %    mid.sentence        in the middle of a sentence: comma needed
  647. %                    if more sentence is output
  648. %    after.sentence        just after a sentence: period needed
  649. %    after.block        just after a block (and sentence):
  650. %                    period and \newblock needed.
  651. % Note: These styles don't use after.sentence
  652. %
  653. % VAR: output.state : INTEGER        -- state variable for output
  654. %
  655. % The output.nonnull function saves its argument (assumed to be nonnull)
  656. % on the stack, and writes the old saved value followed by any needed
  657. % separator.  The ordering of the tests is decreasing frequency of
  658. % occurrence.
  659. %
  660. % output.nonnull(s) ==
  661. %  BEGIN
  662. %    s := argument on stack
  663. %    if output.state = mid.sentence then
  664. %        write$(pop() * ", ")
  665. %          -- "pop" isn't a function: just use stack top
  666. %    else
  667. %        if output.state = after.block then
  668. %        write$(add.period$(pop()))
  669. %        newline$
  670. %        write$("\newblock ")
  671. %        else
  672. %        if output.state = before.all then
  673. %            write$(pop())
  674. %        else        -- output.state should be after.sentence
  675. %            write$(add.period$(pop()) * " ")
  676. %        fi
  677. %        fi
  678. %        output.state := mid.sentence
  679. %    fi
  680. %    push s on stack
  681. %  END
  682. %
  683. % The output function calls output.nonnull if its argument is non-empty;
  684. % its argument may be a missing field (thus, not necessarily a string)
  685. %
  686. % output(s) ==
  687. %  BEGIN
  688. %    if not empty$(s) then output.nonnull(s)
  689. %    fi
  690. %  END
  691. %
  692. % The output.check function is the same as the output function except that, if
  693. % necessary, output.check warns the user that the t field shouldn't be empty
  694. % (this is because it probably won't be a good reference without the field;
  695. % the entry functions try to make the formatting look reasonable even when
  696. % such fields are empty).
  697. %
  698. % output.check(s,t) ==
  699. %  BEGIN
  700. %    if empty$(s) then
  701. %        warning$("empty " * t * " in " * cite$)
  702. %    else output.nonnull(s)
  703. %    fi
  704. %  END
  705. %
  706. % The output.bibitem function writes the \bibitem for the current entry
  707. % (the label should already have been set up), and sets up the separator
  708. % state for the output functions.  And, it leaves a string on the stack
  709. % as per the output convention.
  710. %
  711. % output.bibitem ==
  712. %  BEGIN
  713. %    newline$
  714. %    write$("\bibitem[")    % for alphabetic labels,
  715. %    write$(label)        % these three lines
  716. %    write$("]{")        % are used
  717. %    write$("\bibitem{")        % this line for numeric labels
  718. %    write$(cite$)
  719. %    write$("}")
  720. %    push "" on stack
  721. %    output.state := before.all
  722. %  END
  723. %
  724. % The fin.entry function finishes off an entry by adding a period to the
  725. % string remaining on the stack.  If the state is still before.all
  726. % then nothing was produced for this entry, so the result will look bad,
  727. % but the user deserves it. (We don't omit the whole entry because the
  728. % entry was cited, and a bibitem is needed to define the citation label.)
  729. %
  730. % fin.entry ==
  731. %  BEGIN
  732. %    write$(add.period$(pop()))
  733. %    newline$
  734. %  END
  735. %
  736. % The new.block function prepares for a new block to be output, and
  737. % new.sentence prepares for a new sentence.
  738. %
  739. % new.block ==
  740. %  BEGIN
  741. %    if output.state <> before.all then
  742. %        output.state := after.block
  743. %    fi
  744. %  END
  745. %
  746. % new.sentence ==
  747. %  BEGIN
  748. %    if output.state <> after.block then
  749. %        if output.state <> before.all then
  750. %        output.state :=  after.sentence
  751. %        fi
  752. %    fi
  753. %  END
  754. %
  755.  
  756. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  757.  
  758. FUNCTION {init.state.consts}
  759. { #0 'before.all :=
  760.   #1 'mid.sentence :=
  761.   #2 'after.sentence :=
  762.   #3 'after.block :=
  763. }
  764.  
  765. % the variables s and t are temporary string holders
  766.  
  767. STRINGS { s t }
  768.  
  769. FUNCTION {output.nonnull}
  770. { 's :=
  771.   output.state mid.sentence =
  772.     { ", " * write$ }
  773.     { output.state after.block =
  774. #if !COMMA_DELIMIT
  775.     { add.period$ write$
  776. #else COMMA_DELIMIT
  777.     { "," * write$
  778. #endif
  779.       newline$
  780.       "\newblock " write$
  781.     }
  782.     { output.state before.all =
  783.         'write$
  784.         { add.period$ " " * write$ }
  785.       if$
  786.     }
  787.       if$
  788.       mid.sentence 'output.state :=
  789.     }
  790.   if$
  791.   s
  792. }
  793.  
  794. FUNCTION {output}
  795. { duplicate$ empty$
  796.     'pop$
  797.     'output.nonnull
  798.   if$
  799. }
  800.  
  801. FUNCTION {output.check}
  802. { 't :=
  803.   duplicate$ empty$
  804.     { pop$ "empty " t * " in " * cite$ * warning$ }
  805.     'output.nonnull
  806.   if$
  807. }
  808.  
  809. #if NAMED_REFS
  810. %                    apalike needs this function because
  811. %                    the year has special punctuation;
  812. %                    apalike ignores the month
  813. FUNCTION {output.year.check}
  814. { year empty$
  815.     { "empty year in " cite$ * warning$ }
  816.     { write$
  817.       " (" year * extra.label * ")" *
  818.       mid.sentence 'output.state :=
  819.     }
  820.   if$
  821. }
  822. #endif NAMED_REFS
  823.  
  824. FUNCTION {output.bibitem}
  825. { newline$
  826. #if LAB_ALPH
  827.   "\bibitem[" write$
  828.   label write$
  829.   "]{" write$
  830. #else
  831.   "\bibitem{" write$
  832. #endif LAB_ALPH
  833.   cite$ write$
  834.   "}" write$
  835.   newline$
  836.   ""
  837.   before.all 'output.state :=
  838. }
  839.  
  840. % This function finishes all entries.
  841.  
  842. FUNCTION {fin.entry}
  843. { add.period$
  844.   write$
  845.   newline$
  846. }
  847.  
  848. FUNCTION {new.block}
  849. { output.state before.all =
  850.     'skip$
  851.     { after.block 'output.state := }
  852.   if$
  853. }
  854.  
  855. FUNCTION {new.sentence}
  856. #if !COMMA_DELIMIT
  857. { output.state after.block =
  858.     'skip$
  859.     { output.state before.all =
  860.     'skip$
  861.     { after.sentence 'output.state := }
  862.       if$
  863.     }
  864.   if$
  865. #else COMMA_DELIMIT
  866. { skip$
  867. #endif
  868. }
  869.  
  870. % These three functions pop one or two (integer) arguments from the stack
  871. % and push a single one, either 0 or 1.
  872. % The 'skip$ in the `and' and `or' functions are used because
  873. % the corresponding if$ would be idempotent
  874.  
  875. FUNCTION {not}
  876. {   { #0 }
  877.     { #1 }
  878.   if$
  879. }
  880.  
  881. FUNCTION {and}
  882. {   'skip$
  883.     { pop$ #0 }
  884.   if$
  885. }
  886.  
  887. FUNCTION {or}
  888. {   { pop$ #1 }
  889.     'skip$
  890.   if$
  891. }
  892.  
  893. % Sometimes we begin a new block only if the block will be big enough.  The
  894. % new.block.checka function issues a new.block if its argument is nonempty;
  895. % new.block.checkb does the same if either of its TWO arguments is nonempty.
  896.  
  897. #if !NAMED_REFS
  898. FUNCTION {new.block.checka}
  899. { empty$
  900.     'skip$
  901.     'new.block
  902.   if$
  903. }
  904. #endif !NAMED_REFS
  905.  
  906. FUNCTION {new.block.checkb}
  907. { empty$
  908.   swap$ empty$
  909.   and
  910.     'skip$
  911.     'new.block
  912.   if$
  913. }
  914.  
  915. #if !NAMED_REFS
  916. % The new.sentence.check functions are analogous.
  917.  
  918. FUNCTION {new.sentence.checka}
  919. { empty$
  920.     'skip$
  921.     'new.sentence
  922.   if$
  923. }
  924.  
  925. FUNCTION {new.sentence.checkb}
  926. { empty$
  927.   swap$ empty$
  928.   and
  929.     'skip$
  930.     'new.sentence
  931.   if$
  932. }
  933. #endif !NAMED_REFS
  934.  
  935. % Here are some functions for formatting chunks of an entry.
  936. % By convention they either produce a string that can be followed by
  937. % a comma or period (using add.period$, so it is OK to end in a period),
  938. % or they produce the null string.
  939. %
  940. % A useful utility is the field.or.null function, which checks if the
  941. % argument is the result of pushing a `missing' field (one for which no
  942. % assignment was made when the current entry was read in from the database)
  943. % or the result of pushing a string having no non-white-space characters.
  944. % It returns the null string if so, otherwise it returns the field string.
  945. % Its main (but not only) purpose is to guarantee that what's left on the
  946. % stack is a string rather than a missing field.
  947. %
  948. % field.or.null(s) ==
  949. %  BEGIN
  950. %    if empty$(s) then return ""
  951. %    else return s
  952. %  END
  953. %
  954. % Another helper function is emphasize, which returns the argument emphazised,
  955. % if that is non-empty, otherwise it returns the null string.  Italic
  956. % corrections aren't used, so this function should be used when punctation
  957. % will follow the result.
  958. %
  959. % emphasize(s) ==
  960. %  BEGIN
  961. %    if empty$(s) then return ""
  962. %    else return "{\em " * s * "}"
  963. %
  964. % The format.names function formats the argument (which should be in
  965. % BibTeX name format) into "First Von Last, Junior", separated by commas
  966. % and with an "and" before the last (but ending with "et~al." if the last
  967. % of multiple authors is "others").  This function's argument should always
  968. % contain at least one name.
  969. %
  970. % VAR: nameptr, namesleft, numnames: INTEGER
  971. % pseudoVAR: nameresult: STRING        (it's what's accumulated on the stack)
  972. %
  973. % format.names(s) ==
  974. %  BEGIN
  975. %    nameptr := 1
  976. %    numnames := num.names$(s)
  977. %    namesleft := numnames
  978. %    while namesleft > 0
  979. %      do
  980. %                % for full names:
  981. %        t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
  982. %                % for abbreviated first names:
  983. %        t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
  984. %        if nameptr > 1 then
  985. %        if namesleft > 1 then nameresult := nameresult * ", " * t
  986. %        else if numnames > 2
  987. %               then nameresult := nameresult * ","
  988. %             fi
  989. %             if t = "others"
  990. %               then nameresult := nameresult * " et~al."
  991. %               else nameresult := nameresult * " and " * t
  992. %             fi
  993. %        fi
  994. %        else nameresult := t
  995. %        fi
  996. %        nameptr := nameptr + 1
  997. %        namesleft := namesleft - 1
  998. %      od
  999. %    return nameresult
  1000. %  END
  1001. %
  1002. % The format.authors function returns the result of format.names(author)
  1003. % if the author is present, or else it returns the null string
  1004. %
  1005. % format.authors ==
  1006. %  BEGIN
  1007. %    if empty$(author) then return ""
  1008. %    else return format.names(author)
  1009. %    fi
  1010. %  END
  1011. %
  1012. % Format.editors is like format.authors, but it uses the editor field,
  1013. % and appends ", editor" or ", editors"
  1014. %
  1015. % format.editors ==
  1016. %  BEGIN
  1017. %    if empty$(editor) then return ""
  1018. %    else
  1019. %        if num.names$(editor) > 1 then
  1020. %        return format.names(editor) * ", editors"
  1021. %        else
  1022. %        return format.names(editor) * ", editor"
  1023. %        fi
  1024. %    fi
  1025. %  END
  1026. %
  1027. % Other formatting functions are similar, so no "comment version" will be
  1028. % given for them.
  1029. %
  1030. % The `pop$' in this function gets rid of the duplicate `empty' value and
  1031. % the `skip$' returns the duplicate field value
  1032.  
  1033. FUNCTION {field.or.null}
  1034. { duplicate$ empty$
  1035.     { pop$ "" }
  1036.     'skip$
  1037.   if$
  1038. }
  1039.  
  1040. FUNCTION {emphasize}
  1041. { duplicate$ empty$
  1042.     { pop$ "" }
  1043.     { "{\em " swap$ * "}" * }
  1044.   if$
  1045. }
  1046.  
  1047. #if CSC_NAMES
  1048. FUNCTION {caps}
  1049. { duplicate$ empty$
  1050.     { pop$ "" }
  1051.     { "{\sc " swap$ * "}" * }
  1052.   if$
  1053. }
  1054. #endif
  1055.  
  1056. #if BOLD_VOL
  1057. FUNCTION {embolden}
  1058. { duplicate$ empty$
  1059.     { pop$ "" }
  1060.     { "{\bf " swap$ * "}" * }
  1061.   if$
  1062. }
  1063. #endif
  1064.  
  1065. #if BRACKET_NOTE
  1066. FUNCTION {bracket}
  1067. { duplicate$ empty$
  1068.     { pop$ "" }
  1069.     { "[" swap$ * "]" * }
  1070.   if$
  1071. }
  1072. #endif
  1073.  
  1074. #if PAREN_DATE
  1075. FUNCTION {paren}
  1076. { duplicate$ empty$
  1077.     { pop$ "" }
  1078.     { "(" swap$ * ")" * }
  1079.   if$
  1080. }
  1081. #endif
  1082.  
  1083. INTEGERS { nameptr namesleft numnames }
  1084.  
  1085. #if MAX_NAMES
  1086. INTEGERS { etal }
  1087. #endif
  1088.  
  1089. FUNCTION {format.names}
  1090. { 's :=
  1091.   #1 'nameptr :=
  1092.   s num.names$ 'numnames :=
  1093. #if !MAX_NAMES
  1094.   numnames 'namesleft :=
  1095. #else MAX_NAMES
  1096.   numnames #MAX_NAMES >
  1097.   s numnames "{ll}" format.name$ "others" = numnames #MIN_NAMES > and
  1098.   or 'etal :=
  1099.   etal
  1100.     { #MIN_NAMES #1 + 'namesleft := }
  1101.     { numnames 'namesleft := }
  1102.   if$
  1103. #endif
  1104.     { namesleft #0 > }
  1105. #if NAME_FULL
  1106. #if !NAME_INVERT
  1107.     { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
  1108. #else NAME_INVERT
  1109.     { s nameptr "{vv~}{ll}{, jj}{, ff}" format.name$ 't :=
  1110. #endif
  1111. #else
  1112. #if !NAME_INVERT
  1113.     { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
  1114. #else NAME_INVERT
  1115.     { s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't :=   % last name first
  1116. #endif
  1117. #endif NAME_FULL
  1118. #if NAME_UPPER
  1119.       t "others" =
  1120.     'skip$
  1121.     { t "u" change.case$ 't := }
  1122.       if$
  1123. #endif
  1124. #if CSC_NAMES
  1125.       t "others" =
  1126.     'skip$
  1127.     { t caps 't := }
  1128.       if$
  1129. #endif
  1130.       nameptr #1 >
  1131.     { namesleft #1 >
  1132.         { ", " * t * }
  1133. #if !MAX_NAMES
  1134.         { numnames #2 >
  1135.         { "," * }
  1136.         'skip$
  1137.           if$
  1138.           t "others" =
  1139. #if !ETAL_EMPH
  1140.         { " et~al." * }
  1141. #else ETAL_EMPH
  1142.         { " {\em et~al.}" * }
  1143. #endif ETAL_EMPH
  1144.         { " and " * t * }
  1145.           if$
  1146.         }
  1147. #else MAX_NAMES
  1148.         { nameptr #2 >
  1149.         { "," * }
  1150.         'skip$
  1151.           if$
  1152.           t "others" =
  1153.           etal or
  1154. #if !ETAL_EMPH
  1155.         { " et~al." * }
  1156. #else ETAL_EMPH
  1157.         { " {\em et~al.}" * }
  1158. #endif ETAL_EMPH
  1159.         { " and " * t * }
  1160.           if$
  1161.         }
  1162. #endif
  1163.       if$
  1164.     }
  1165.     't
  1166.       if$
  1167.       nameptr #1 + 'nameptr :=
  1168.       namesleft #1 - 'namesleft :=
  1169.     }
  1170.   while$
  1171. }
  1172.  
  1173. FUNCTION {format.authors}
  1174. { author empty$
  1175.     { "" }
  1176.     { author format.names }
  1177.   if$
  1178. }
  1179.  
  1180. #if NAMED_REFS
  1181. FUNCTION {format.key}            % this function is just for apalike
  1182. { empty$
  1183.     { key field.or.null }
  1184.     { "" }
  1185.   if$
  1186. }
  1187. #endif NAMED_REFS
  1188.  
  1189. FUNCTION {format.editors}
  1190. { editor empty$
  1191.     { "" }
  1192.     { editor format.names
  1193.       editor num.names$ #1 >
  1194.     { ", editors" * }
  1195.     { ", editor" * }
  1196.       if$
  1197.     }
  1198.   if$
  1199. }
  1200.  
  1201. #if EDIT_VAR
  1202. FUNCTION {format.edited}
  1203. { editor empty$
  1204.     { "" }
  1205.     { "edited by " editor format.names * }
  1206.   if$
  1207. }
  1208. #endif
  1209.  
  1210. % The format.title function is used for non-book-like titles.
  1211. % For most styles we convert to lowercase (except for the very first letter,
  1212. % and except for the first one after a colon (followed by whitespace)),
  1213. % and hope the user has brace-surrounded words that need to stay capitilized;
  1214. % for some styles, however, we leave it as it is in the database.
  1215.  
  1216. FUNCTION {format.title}
  1217. { title empty$
  1218.     { "" }
  1219. #if ATIT_LOWER
  1220.     { title "t" change.case$ }
  1221. #else
  1222.     'title
  1223. #endif ATIT_LOWER
  1224.   if$
  1225. }
  1226.  
  1227. % By default, BibTeX sets the global integer variable global.max$ to the BibTeX
  1228. % constant glob_str_size, the maximum length of a global string variable.
  1229. % Analogously, BibTeX sets the global integer variable entry.max$ to
  1230. % ent_str_size, the maximum length of an entry string variable.
  1231. % The style designer may change these if necessary (but this is unlikely)
  1232.  
  1233. % The n.dashify function makes each single `-' in a string a double `--'
  1234. % if it's not already
  1235. %
  1236. % pseudoVAR: pageresult: STRING        (it's what's accumulated on the stack)
  1237. %
  1238. % n.dashify(s) ==
  1239. %  BEGIN
  1240. %    t := s
  1241. %    pageresult := ""
  1242. %    while (not empty$(t))
  1243. %      do
  1244. %        if (first character of t = "-")
  1245. %          then
  1246. %        if (next character isn't)
  1247. %          then
  1248. %            pageresult := pageresult * "--"
  1249. %            t := t with the "-" removed
  1250. %          else
  1251. %            while (first character of t = "-")
  1252. %              do
  1253. %            pageresult := pageresult * "-"
  1254. %            t := t with the "-" removed
  1255. %              od
  1256. %        fi
  1257. %          else
  1258. %        pageresult := pageresult * the first character
  1259. %        t := t with the first character removed
  1260. %        fi
  1261. %      od
  1262. %    return pageresult
  1263. %  END
  1264.  
  1265. FUNCTION {n.dashify}
  1266. { 't :=
  1267.   ""
  1268.     { t empty$ not }
  1269.     { t #1 #1 substring$ "-" =
  1270.     { t #1 #2 substring$ "--" = not
  1271.         { "--" *
  1272.           t #2 global.max$ substring$ 't :=
  1273.         }
  1274.         {   { t #1 #1 substring$ "-" = }
  1275.         { "-" *
  1276.           t #2 global.max$ substring$ 't :=
  1277.         }
  1278.           while$
  1279.         }
  1280.       if$
  1281.     }
  1282.     { t #1 #1 substring$ *
  1283.       t #2 global.max$ substring$ 't :=
  1284.     }
  1285.       if$
  1286.     }
  1287.   while$
  1288. }
  1289.  
  1290. #define TEMP 0
  1291. #if PAGE_START_J
  1292. #define TEMP 1
  1293. #endif
  1294. #if PAGE_START_O
  1295. #define TEMP 1
  1296. #endif
  1297.  
  1298. #if TEMP
  1299. FUNCTION {first.page}
  1300. { 't :=
  1301.   ""
  1302.     {  t empty$ not t #1 #1 substring$ "-" = not and }
  1303.     { t #1 #1 substring$ *
  1304.       t #2 global.max$ substring$ 't :=
  1305.     }
  1306.   while$
  1307. }
  1308. #endif
  1309.  
  1310. #if !NAMED_REFS
  1311. % The format.date function is for the month and year, but we give a warning if
  1312. % there's an empty year but the month is there, and we return the empty string
  1313. % if they're both empty.
  1314.  
  1315. FUNCTION {format.date}
  1316. { year empty$
  1317. #if !MONTH_SUPPRESS
  1318.     { month empty$
  1319.     { "" }
  1320.     { "there's a month but no year in " cite$ * warning$
  1321.       month
  1322.     }
  1323.       if$
  1324.     }
  1325.     { month empty$
  1326.     'year
  1327.     { month " " * year * }
  1328.       if$
  1329.     }
  1330. #else MONTH_SUPPRESS
  1331.     { "" }
  1332.     'year
  1333. #endif
  1334.   if$
  1335. }
  1336. #endif !NAMED_REFS
  1337.  
  1338. % The format.btitle is for formatting the title field when it is a book-like
  1339. % entry---the style used here keeps it in uppers-and-lowers and emphasizes it.
  1340.  
  1341. FUNCTION {format.btitle}
  1342. { title emphasize
  1343. }
  1344.  
  1345. % For several functions we'll need to connect two strings with a
  1346. % tie (~) if the second one isn't very long (fewer than 3 characters).
  1347. % The tie.or.space.connect function does that.  It concatenates the two
  1348. % strings on top of the stack, along with either a tie or space between
  1349. % them, and puts this concatenation back onto the stack:
  1350. %
  1351. % tie.or.space.connect(str1,str2) ==
  1352. %    BEGIN
  1353. %    if text.length$(str2) < 3
  1354. %      then return the concatenation of str1, "~", and str2
  1355. %      else return the concatenation of str1, " ", and str2
  1356. %    END
  1357.  
  1358. FUNCTION {tie.or.space.connect}
  1359. { duplicate$ text.length$ #3 <
  1360.     { "~" }
  1361.     { " " }
  1362.   if$
  1363.   swap$ * *
  1364. }
  1365.  
  1366. % The either.or.check function complains if both fields or an either-or pair
  1367. % are nonempty.
  1368. %
  1369. % either.or.check(t,s) ==
  1370. %  BEGIN
  1371. %    if empty$(s) then
  1372. %        warning$(can't use both " * t * " fields in " * cite$)
  1373. %    fi
  1374. %  END
  1375.  
  1376. FUNCTION {either.or.check}
  1377. { empty$
  1378.     'pop$
  1379.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  1380.   if$
  1381. }
  1382.  
  1383. % The format.bvolume function is for formatting the volume and perhaps
  1384. % series name of a multivolume work.  If both a volume and a series field
  1385. % are there, we assume the series field is the title of the whole multivolume
  1386. % work (the title field should be the title of the thing being referred to),
  1387. % and we add an "of <series>".  This function is called in mid-sentence.
  1388.  
  1389. FUNCTION {format.bvolume}
  1390. { volume empty$
  1391.     { "" }
  1392.     { "volume" volume tie.or.space.connect
  1393.       series empty$
  1394.     'skip$
  1395.     { " of " * series emphasize * }
  1396.       if$
  1397.       "volume and number" number either.or.check
  1398.     }
  1399.   if$
  1400. }
  1401.  
  1402. % The format.number.series function is for formatting the series name
  1403. % and perhaps number of a work in a series.  This function is similar to
  1404. % format.bvolume, although for this one the series must exist (and the
  1405. % volume must not exist).  If the number field is empty we output either
  1406. % the series field unchanged if it exists or else the null string.
  1407. % If both the number and series fields are there we assume the series field
  1408. % gives the name of the whole series (the title field should be the title
  1409. % of the work being one referred to), and we add an "in <series>".
  1410. % We capitilize Number when this function is used at the beginning of a block.
  1411.  
  1412. FUNCTION {format.number.series}
  1413. { volume empty$
  1414.     { number empty$
  1415.     { series field.or.null }
  1416.     { output.state mid.sentence =
  1417.         { "number" }
  1418.         { "Number" }
  1419.       if$
  1420.       number tie.or.space.connect
  1421.       series empty$
  1422.         { "there's a number but no series in " cite$ * warning$ }
  1423.         { " in " * series * }
  1424.       if$
  1425.     }
  1426.       if$
  1427.     }
  1428.     { "" }
  1429.   if$
  1430. }
  1431.  
  1432. % The format.edition function appends " edition" to the edition, if present.
  1433. % We lowercase the edition (it should be something like "Third"), because
  1434. % this doesn't start a sentence.
  1435.  
  1436. FUNCTION {format.edition}
  1437. { edition empty$
  1438.     { "" }
  1439.     { output.state mid.sentence =
  1440.     { edition "l" change.case$ " edition" * }
  1441.     { edition "t" change.case$ " edition" * }
  1442.       if$
  1443.     }
  1444.   if$
  1445. }
  1446.  
  1447. % The format.pages function is used for formatting a page range in a book
  1448. % (and in rare circumstances, an article).
  1449. %
  1450. % The multi.page.check function examines the page field for a "-" or "," or "+"
  1451. % so that format.pages can use "page" instead of "pages" if none exists.
  1452. % Note: global.max$ here means "take the rest of the string"
  1453. %
  1454. % VAR: multiresult: INTEGER    (actually, a boolean)
  1455. %
  1456. % multi.page.check(s) ==
  1457. %  BEGIN
  1458. %    t := s
  1459. %    multiresult := false
  1460. %    while ((not multiresult) and (not empty$(t)))
  1461. %      do
  1462. %        if (first character of t = "-" or "," or "+")
  1463. %          then multiresult := true
  1464. %          else t := t with the first character removed
  1465. %        fi
  1466. %      od
  1467. %    return multiresult
  1468. %  END
  1469.  
  1470. INTEGERS { multiresult }
  1471.  
  1472. FUNCTION {multi.page.check}
  1473. { 't :=
  1474.   #0 'multiresult :=
  1475.     { multiresult not
  1476.       t empty$ not
  1477.       and
  1478.     }
  1479.     { t #1 #1 substring$
  1480.       duplicate$ "-" =
  1481.       swap$ duplicate$ "," =
  1482.       swap$ "+" =
  1483.       or or
  1484.     { #1 'multiresult := }
  1485.     { t #2 global.max$ substring$ 't := }
  1486.       if$
  1487.     }
  1488.   while$
  1489.   multiresult
  1490. }
  1491.  
  1492. % This function doesn't begin a sentence so "pages" isn't capitalized.
  1493. % Other functions that use this should keep that in mind.
  1494.  
  1495. FUNCTION {format.pages}
  1496. { pages empty$
  1497.     { "" }
  1498.     { pages multi.page.check
  1499. #if !PAGE_ABBREV
  1500.     { "pages" pages n.dashify tie.or.space.connect }
  1501.     { "page" pages tie.or.space.connect }
  1502. #else PAGE_ABBREV
  1503.     { "pp." pages n.dashify tie.or.space.connect }
  1504.     { "p." pages tie.or.space.connect }
  1505. #endif
  1506.       if$
  1507.     }
  1508.   if$
  1509. }
  1510.  
  1511. #if TEMP
  1512. FUNCTION {format.pages.a}
  1513. { pages empty$
  1514.     { "" }
  1515. #if !PAGE_ABBREV
  1516.     { "page" pages first.page tie.or.space.connect }
  1517. #else PAGE_ABBREV
  1518.     { "p." pages first.page tie.or.space.connect }
  1519. #endif
  1520.   if$
  1521. }
  1522. #endif
  1523.  
  1524. % The format.vol.num.pages function is for the volume, number, and page range
  1525. % of a journal article.  We use the format:  vol(number):pages, with some
  1526. % variations for empty fields.  This doesn't begin a sentence.
  1527.  
  1528. FUNCTION {format.vol.num.pages}
  1529. #if !BOLD_VOL
  1530. { volume field.or.null
  1531. #else BOLD_VOL
  1532. { volume field.or.null embolden
  1533. #endif
  1534. #if VOLUME_SPACE
  1535.   " " swap$ * *
  1536. #endif
  1537. #if !NUM_SUPPRESS
  1538.   number empty$
  1539.     'skip$
  1540.     { "(" number * ")" * *
  1541.       volume empty$
  1542.     { "there's a number but no volume in " cite$ * warning$ }
  1543.     'skip$
  1544.       if$
  1545.     }
  1546.   if$
  1547. #endif
  1548. #if DATE_FIRST
  1549.   format.date empty$
  1550.     'skip$
  1551.     { duplicate$ empty$
  1552.     { pop$ format.date paren }
  1553.         { " " * format.date paren * }
  1554.       if$
  1555.     }
  1556.   if$
  1557. #endif
  1558.   pages empty$
  1559.     'skip$
  1560.     { duplicate$ empty$
  1561. #if !PAGE_START_J
  1562.     { pop$ format.pages }
  1563. #else PAGE_START_J
  1564.     { pop$ format.pages.a }
  1565. #endif
  1566. #if !PAGE_START_J
  1567. #if !DATE_FIRST
  1568. #if !VOLUME_SPACE
  1569.     { ":" * pages n.dashify * }
  1570. #else VOLUME_SPACE
  1571.     { ", " * pages n.dashify * }
  1572. #endif
  1573. #else DATE_FIRST
  1574.     { " " * pages n.dashify *}
  1575. #endif
  1576. #else PAGE_START_J
  1577. #if !DATE_FIRST
  1578. #if !VOLUME_SPACE
  1579.     { ":" * pages first.page * }
  1580. #else VOLUME_SPACE
  1581.     { ", " * pages first.page * }
  1582. #endif
  1583. #else DATE_FIRST
  1584.     { " " * pages first.page *}
  1585. #endif
  1586. #endif
  1587.       if$
  1588.     }
  1589.   if$
  1590. }
  1591.  
  1592.  
  1593. % The format.chapter.pages, if the chapter is present, puts whatever is in the
  1594. % type field (or else "chapter" if type is empty) in front of a chapter number.
  1595. % It then appends the pages, if present.  This doesn't begin a sentence.
  1596.  
  1597. FUNCTION {format.chapter.pages}
  1598. { chapter empty$
  1599.     'format.pages
  1600.     { type empty$
  1601.     { "chapter" }
  1602.     { type "l" change.case$ }
  1603.       if$
  1604.       chapter tie.or.space.connect
  1605.       pages empty$
  1606.     'skip$
  1607.     { ", " * format.pages * }
  1608.       if$
  1609.     }
  1610.   if$
  1611. }
  1612.  
  1613. % The format.in.ed.booktitle function is used for starting out a sentence
  1614. % that begins "In <booktitle>", putting an editor before the title if one
  1615. % exists.
  1616.  
  1617. FUNCTION {format.in.ed.booktitle}
  1618. { booktitle empty$
  1619.     { "" }
  1620.     { editor empty$
  1621. #if !COMMA_DELIMIT
  1622.     { "In " booktitle emphasize * }
  1623. #if !EDIT_VAR
  1624.     { "In " format.editors * ", " * booktitle emphasize * }
  1625. #else EDIT_VAR
  1626.     { "In " booktitle emphasize * ", " * format.edited * }
  1627. #endif
  1628. #else COMMA_DELIMIT
  1629.     { "in " booktitle emphasize * }
  1630. #if !EDIT_VAR
  1631.     { "in " format.editors * ", " * booktitle emphasize * }
  1632. #else EDIT_VAR
  1633.     { "in " booktitle emphasize * ", " * format.edited * }
  1634. #endif
  1635. #endif
  1636.       if$
  1637.     }
  1638.   if$
  1639. }
  1640.  
  1641. #if !NAMED_REFS
  1642. % The function empty.misc.check complains if all six fields are empty, and
  1643. % if there's been no sorting or alphabetic-label complaint.
  1644.  
  1645. FUNCTION {empty.misc.check}
  1646. { author empty$ title empty$ howpublished empty$
  1647.   month empty$ year empty$ note empty$
  1648.   and and and and and
  1649. #if SORTED
  1650.   key empty$ not and
  1651. #else !SORTED
  1652. #if LAB_ALPH
  1653.   key empty$ not and
  1654. #endif LAB_ALPH
  1655. #endif SORTED
  1656.     { "all relevant fields are empty in " cite$ * warning$ }
  1657.     'skip$
  1658.   if$
  1659. }
  1660. #endif
  1661.  
  1662. % The function format.thesis.type returns either the (case-changed) type field,
  1663. % if it is defined, or else the default string already on the stack
  1664. % (like "Master's thesis" or "PhD thesis").
  1665.  
  1666. FUNCTION {format.thesis.type}
  1667. { type empty$
  1668.     'skip$
  1669.     { pop$
  1670.       type "t" change.case$
  1671.     }
  1672.   if$
  1673. }
  1674.  
  1675. % The function format.tr.number makes a string starting with "Technical Report"
  1676. % (or type, if that field is defined), followed by the number if there is one;
  1677. % it returns the starting part (with a case change) even if there is no number.
  1678. % This is used at the beginning of a sentence.
  1679.  
  1680. FUNCTION {format.tr.number}
  1681. { type empty$
  1682.     { "Technical Report" }
  1683.     'type
  1684.   if$
  1685.   number empty$
  1686.     { "t" change.case$ }
  1687.     { number tie.or.space.connect }
  1688.   if$
  1689. }
  1690.  
  1691. % Now come the cross-referencing functions (these are invoked because
  1692. % one entry in the database file(s) cross-references another, by giving
  1693. % the other entry's database key in a `crossref' field).  This feature
  1694. % allows one or more titled things that are part of a larger titled
  1695. % thing to cross-reference the larger thing.  These styles allow for
  1696. % five posibilities: (1) an ARTICLE may cross-reference an ARTICLE;
  1697. % (2) a BOOK, (3) INBOOK, or (4) INCOLLECTION may cross-reference a BOOK;
  1698. % or (5) an INPROCEEDINGS may cross-reference a PROCEEDINGS.
  1699. % Each of these is explained in more detail later.
  1700. %
  1701. % An ARTICLE entry type may cross reference another ARTICLE (this is
  1702. % intended for when an entire journal is devoted to a single topic---
  1703. % but since there is no JOURNAL entry type, the journal, too, should be
  1704. % classified as an ARTICLE but without the author and title fields).
  1705. % This will result in two warning messages for the journal's entry
  1706. % if it's included in the reference list, but such is life.
  1707. %
  1708. % format.article.crossref ==
  1709. %  BEGIN
  1710. %    if empty$(key) then
  1711. %        if empty$(journal) then
  1712. %        warning$("need key or journal for " * cite$ *
  1713. %                        " to crossref " * crossref)
  1714. %        return(" \cite{" * crossref * "}")
  1715. %        else
  1716. %        return("In " * emphazise.correct (journal) *
  1717. %                        " \cite{" * crossref * "}")
  1718. %        fi
  1719. %    else
  1720. %        return("In " * key * " \cite{" * crossref * "}")
  1721. %    fi
  1722. %  END
  1723. %
  1724. % The other cross-referencing functions are similar, so no "comment version"
  1725. % will be given for them.
  1726.  
  1727. #if !NAMED_REFS
  1728. FUNCTION {format.article.crossref}
  1729. { key empty$
  1730.     { journal empty$
  1731.     { "need key or journal for " cite$ * " to crossref " * crossref *
  1732.       warning$
  1733.       ""
  1734.     }
  1735. #if !JOUR_DEEMPH
  1736.     { "In {\em " journal * "\/}" * }
  1737. #else JOUR_DEEMPH
  1738.     { "In " journal * }
  1739. #endif
  1740.       if$
  1741.     }
  1742.     { "In " key * }
  1743.   if$
  1744.   " \cite{" * crossref * "}" *
  1745. }
  1746. #else NAMED_REFS
  1747. FUNCTION {format.article.crossref}
  1748. { "In"                            % this is for apalike
  1749.   " \cite{" * crossref * "}" *
  1750. }
  1751. #endif NAMED_REFS
  1752.  
  1753. #if !NAMED_REFS
  1754. % We use just the last names of editors for a cross reference: either
  1755. % "editor", or "editor1 and editor2", or "editor1 et~al." depending on
  1756. % whether there are one, or two, or more than two editors.
  1757.  
  1758. FUNCTION {format.crossref.editor}
  1759. #if !CSC_NAMES
  1760. { editor #1 "{vv~}{ll}" format.name$
  1761. #else CSC_NAMES
  1762. { editor #1 "{vv~}{ll}" format.name$ caps
  1763. #endif
  1764.   editor num.names$ duplicate$
  1765.   #2 >
  1766. #if !ETAL_EMPH
  1767.     { pop$ " et~al." * }
  1768. #else ETAL_EMPH
  1769.     { pop$ " {\em et~al.}" * }
  1770. #endif ETAL_EMPH
  1771.     { #2 <
  1772.     'skip$
  1773.     { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1774. #if !ETAL_EMPH
  1775.         { " et~al." * }
  1776. #else ETAL_EMPH
  1777.         { " {\em et~al.}" * }
  1778. #endif ETAL_EMPH
  1779. #if !CSC_NAMES
  1780.         { " and " * editor #2 "{vv~}{ll}" format.name$ * }
  1781. #else CSC_NAMES
  1782.         { " and " * editor #2 "{vv~}{ll}" format.name$ caps * }
  1783. #endif
  1784.       if$
  1785.     }
  1786.       if$
  1787.     }
  1788.   if$
  1789. }
  1790. #endif
  1791.  
  1792. % A BOOK (or INBOOK) entry type (assumed to be for a single volume in a
  1793. % multivolume work) may cross reference another BOOK (the entire multivolume).
  1794. % Usually there will be an editor, in which case we use that to construct the
  1795. % cross reference; otherwise we use a nonempty key field or else the series
  1796. % field (since the series gives the title of the multivolume work).
  1797.  
  1798. FUNCTION {format.book.crossref}
  1799. { volume empty$
  1800.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  1801.       "In "
  1802.     }
  1803.     { "Volume" volume tie.or.space.connect
  1804.       " of " *
  1805.     }
  1806.   if$
  1807. #if !NAMED_REFS
  1808.   editor empty$
  1809.   editor field.or.null author field.or.null =
  1810.   or
  1811.     { key empty$
  1812.     { series empty$
  1813.         { "need editor, key, or series for " cite$ * " to crossref " *
  1814.           crossref * warning$
  1815.           "" *
  1816.         }
  1817.         { "{\em " * series * "\/}" * }
  1818.       if$
  1819.     }
  1820.     { key * }
  1821.       if$
  1822.     }
  1823.     { format.crossref.editor * }
  1824.   if$
  1825.   " \cite{" * crossref * "}" *
  1826. #else NAMED_REFS
  1827.   "\cite{" * crossref * "}" *                % this is for apalike
  1828. #endif
  1829. }
  1830.  
  1831. % An INCOLLECTION entry type may cross reference a BOOK (assumed to be the
  1832. % collection), or an INPROCEEDINGS may cross reference a PROCEEDINGS.
  1833. % Often there will be an editor, in which case we use that to construct
  1834. % the cross reference; otherwise we use a nonempty key field or else
  1835. % the booktitle field (which gives the cross-referenced work's title).
  1836.  
  1837. #if !NAMED_REFS
  1838. FUNCTION {format.incoll.inproc.crossref}
  1839. { editor empty$
  1840.   editor field.or.null author field.or.null =
  1841.   or
  1842.     { key empty$
  1843.     { booktitle empty$
  1844.         { "need editor, key, or booktitle for " cite$ * " to crossref " *
  1845.           crossref * warning$
  1846.           ""
  1847.         }
  1848.         { "In {\em " booktitle * "\/}" * }
  1849.       if$
  1850.     }
  1851.     { "In " key * }
  1852.       if$
  1853.     }
  1854.     { "In " format.crossref.editor * }
  1855.   if$
  1856.   " \cite{" * crossref * "}" *
  1857. }
  1858. #else NAMED_REFS
  1859. FUNCTION {format.incoll.inproc.crossref}
  1860. { "In"                            % this is for apalike
  1861.   " \cite{" * crossref * "}" *
  1862. }
  1863. #endif NAMED_REFS
  1864.  
  1865. % Now we define the type functions for all entry types that may appear
  1866. % in the .BIB file---e.g., functions like `article' and `book'.  These
  1867. % are the routines that actually generate the .BBL-file output for
  1868. % the entry.  These must all precede the READ command.  In addition, the
  1869. % style designer should have a function `default.type' for unknown types.
  1870. % Note: The fields (within each list) are listed in order of appearance,
  1871. % except as described for an `inbook' or a `proceedings'.
  1872. %
  1873. % The article function is for an article in a journal.  An article may
  1874. % CROSSREF another article.
  1875. %    Required fields: author, title, journal, year
  1876. %    Optional fields: volume, number, pages, month, note
  1877. %
  1878. % article ==
  1879. %  BEGIN
  1880. %    output.bibitem
  1881. %    output.check(format.authors,"author")
  1882. %    new.block
  1883. %    output.check(format.title,"title")
  1884. %    new.block
  1885. %    if missing$(crossref) then
  1886. %        output.check(emphasize(journal),"journal")
  1887. %        output(format.vol.num.pages)
  1888. %        output.check(format.date,"year")
  1889. %       else
  1890. %        output.nonnull(format.article.crossref)
  1891. %        output(format.pages)
  1892. %    fi
  1893. %    new.block
  1894. %    output(note)
  1895. %    fin.entry
  1896. %  END
  1897. %
  1898. % The book function is for a whole book.  A book may CROSSREF another book.
  1899. %    Required fields: author or editor, title, publisher, year
  1900. %    Optional fields: volume or number, series, address, edition, month,
  1901. %            note
  1902. %
  1903. % book ==
  1904. %  BEGIN
  1905. %    if empty$(author) then output.check(format.editors,"author and editor")
  1906. %    else    output.check(format.authors,"author")
  1907. %        if missing$(crossref) then
  1908. %            either.or.check("author and editor",editor)
  1909. %        fi
  1910. %    fi
  1911. %    new.block
  1912. %    output.check(format.btitle,"title")
  1913. %    if missing$(crossref) then
  1914. %        output(format.bvolume)
  1915. %        new.block
  1916. %        output(format.number.series)
  1917. %        new.sentence
  1918. %        output.check(publisher,"publisher")
  1919. %        output(address)
  1920. %       else
  1921. %        new.block
  1922. %        output.nonnull(format.book.crossref)
  1923. %    fi
  1924. %    output(format.edition)
  1925. %    output.check(format.date,"year")
  1926. %    new.block
  1927. %    output(note)
  1928. %    fin.entry
  1929. %  END
  1930. %
  1931. % The other entry functions are all quite similar, so no "comment version"
  1932. % will be given for them.
  1933.  
  1934. FUNCTION {article}
  1935. { output.bibitem
  1936.   format.authors "author" output.check
  1937. #if NAMED_REFS
  1938.   author format.key output                % special for
  1939.   output.year.check                    % apalike
  1940. #endif NAMED_REFS
  1941. #if !ATIT_SUPPRESS
  1942.   new.block
  1943.   format.title "title" output.check
  1944. #endif
  1945.   new.block
  1946.   crossref missing$
  1947. #if !VOLUME_SPACE
  1948. #if !JOUR_DEEMPH
  1949.     { journal emphasize "journal" output.check
  1950. #else JOUR_DEEMPH
  1951.     { journal "journal" output.check
  1952. #endif
  1953. #else VOLUME_SPACE
  1954. #if !JOUR_DEEMPH
  1955.     { journal emphasize
  1956. #else JOUR_DEEMPH
  1957.     { journal field.or.null
  1958. #endif
  1959. #endif
  1960. #if !NAMED_REFS
  1961. #if !DATE_FIRST
  1962. #if !PAREN_DATE
  1963.       format.vol.num.pages output
  1964.       format.date "year" output.check
  1965. #else PAREN_DATE
  1966.       format.vol.num.pages 
  1967.       format.date empty$
  1968.     'skip$
  1969.     { duplicate$ empty$
  1970.         { pop$ format.date paren }
  1971.             { " " * format.date paren * }
  1972.       if$
  1973.     }
  1974.       if$
  1975.       output
  1976. #endif
  1977. #else DATE_FIRST
  1978.       format.vol.num.pages output
  1979. #endif DATE_FIRST
  1980. #else NAMED_REFS
  1981.       format.vol.num.pages output
  1982. #endif NAMED_REFS
  1983.     }
  1984.     { format.article.crossref output.nonnull
  1985.       format.pages output
  1986.     }
  1987.   if$
  1988.   new.block
  1989.   note output
  1990.   fin.entry
  1991. }
  1992.  
  1993. FUNCTION {book}
  1994. { output.bibitem
  1995.   author empty$
  1996. #if !NAMED_REFS
  1997.     { format.editors "author and editor" output.check }
  1998. #else NAMED_REFS
  1999.     { format.editors "author and editor" output.check
  2000.       editor format.key output
  2001.     }
  2002. #endif NAMED_REFS
  2003.     { format.authors output.nonnull
  2004.       crossref missing$
  2005.     { "author and editor" editor either.or.check }
  2006.     'skip$
  2007.       if$
  2008.     }
  2009.   if$
  2010. #if NAMED_REFS
  2011.   output.year.check                % special for apalike
  2012. #endif
  2013.   new.block
  2014.   format.btitle "title" output.check
  2015.   crossref missing$
  2016.     { format.bvolume output
  2017.       new.block
  2018.       format.number.series output
  2019.       new.sentence
  2020.       publisher "publisher" output.check
  2021.       address output
  2022.     }
  2023.     { new.block
  2024.       format.book.crossref output.nonnull
  2025.     }
  2026.   if$
  2027.   format.edition output
  2028. #if !NAMED_REFS
  2029.   format.date "year" output.check
  2030. #endif
  2031.   new.block
  2032.   note output
  2033.   fin.entry
  2034. }
  2035.  
  2036. % A booklet is a bound thing without a publisher or sponsoring institution.
  2037. %    Required: title
  2038. %    Optional: author, howpublished, address, month, year, note
  2039.  
  2040. FUNCTION {booklet}
  2041. { output.bibitem
  2042.   format.authors output
  2043. #if !NAMED_REFS
  2044.   new.block
  2045.   format.title "title" output.check
  2046.   howpublished address new.block.checkb
  2047.   howpublished output
  2048.   address output
  2049.   format.date output
  2050. #else NAMED_REFS
  2051.   author format.key output                % special for
  2052.   output.year.check                    % apalike
  2053.   new.block
  2054.   format.title "title" output.check
  2055.   new.block
  2056.   howpublished output
  2057.   address output
  2058. #endif NAMED_REFS
  2059.   new.block
  2060.   note output
  2061.   fin.entry
  2062. }
  2063.  
  2064. % For the conference entry type, see inproceedings.
  2065.  
  2066. % An inbook is a piece of a book: either a chapter and/or a page range.
  2067. % It may CROSSREF a book.  If there's no volume field, the type field
  2068. % will come before number and series.
  2069. %    Required: author or editor, title, chapter and/or pages, publisher,year
  2070. %    Optional: volume or number, series, type, address, edition, month, note
  2071.  
  2072. FUNCTION {inbook}
  2073. { output.bibitem
  2074.   author empty$
  2075. #if !NAMED_REFS
  2076.     { format.editors "author and editor" output.check }
  2077. #else NAMED_REFS
  2078.     { format.editors "author and editor" output.check
  2079.       editor format.key output
  2080.     }
  2081. #endif
  2082.     { format.authors output.nonnull
  2083.       crossref missing$
  2084.     { "author and editor" editor either.or.check }
  2085.     'skip$
  2086.       if$
  2087.     }
  2088.   if$
  2089. #if NAMED_REFS
  2090.   output.year.check                % special for apalike
  2091. #endif
  2092.   new.block
  2093.   format.btitle "title" output.check
  2094.   crossref missing$
  2095.     { format.bvolume output
  2096.       format.chapter.pages "chapter and pages" output.check
  2097.       new.block
  2098.       format.number.series output
  2099.       new.sentence
  2100.       publisher "publisher" output.check
  2101.       address output
  2102.     }
  2103.     { format.chapter.pages "chapter and pages" output.check
  2104.       new.block
  2105.       format.book.crossref output.nonnull
  2106.     }
  2107.   if$
  2108.   format.edition output
  2109. #if !NAMED_REFS
  2110.   format.date "year" output.check
  2111. #endif
  2112.   new.block
  2113.   note output
  2114.   fin.entry
  2115. }
  2116.  
  2117. % An incollection is like inbook, but where there is a separate title
  2118. % for the referenced thing (and perhaps an editor for the whole).
  2119. % An incollection may CROSSREF a book.
  2120. %    Required: author, title, booktitle, publisher, year
  2121. %    Optional: editor, volume or number, series, type, chapter, pages,
  2122. %            address, edition, month, note
  2123.  
  2124. FUNCTION {incollection}
  2125. { output.bibitem
  2126.   format.authors "author" output.check
  2127. #if NAMED_REFS
  2128.   author format.key output                % special for
  2129.   output.year.check                    % apalike
  2130. #endif NAMED_REFS
  2131. #if !ATIT_SUPPRESS
  2132.   new.block
  2133.   format.title "title" output.check
  2134. #else
  2135. #if !ALT_INCOLL
  2136.   new.block
  2137.   format.title "title" output.check
  2138. #endif !ALT_INCOLL
  2139. #endif !ATIT_SUPPRESS
  2140.   new.block
  2141.   crossref missing$
  2142.     { format.in.ed.booktitle "booktitle" output.check
  2143. #if !ALT_INCOLL
  2144.       format.bvolume output
  2145.       format.number.series output
  2146.       format.chapter.pages output
  2147. #endif !ALT_INCOLL
  2148.       new.sentence
  2149.       publisher "publisher" output.check
  2150.       address output
  2151.       format.edition output
  2152. #if !NAMED_REFS
  2153.       format.date "year" output.check
  2154. #endif !NAMED_REFS
  2155. #if ALT_INCOLL
  2156.       format.bvolume output
  2157.       format.number.series output
  2158.       format.chapter.pages output
  2159. #endif ALT_INCOLL
  2160.     }
  2161.     { format.incoll.inproc.crossref output.nonnull
  2162.       format.chapter.pages output
  2163.     }
  2164.   if$
  2165.   new.block
  2166.   note output
  2167.   fin.entry
  2168. }
  2169.  
  2170. % An inproceedings is an article in a conference proceedings, and it may
  2171. % CROSSREF a proceedings.  If there's no address field, the month (& year)
  2172. % will appear just before note.
  2173. %    Required: author, title, booktitle, year
  2174. %    Optional: editor, volume or number, series, pages, address, month,
  2175. %            organization, publisher, note
  2176.  
  2177. FUNCTION {inproceedings}
  2178. { output.bibitem
  2179.   format.authors "author" output.check
  2180. #if NAMED_REFS
  2181.   author format.key output                % special for
  2182.   output.year.check                    % apalike
  2183. #endif NAMED_REFS
  2184.   new.block
  2185.   format.title "title" output.check
  2186.   new.block
  2187.   crossref missing$
  2188.     { format.in.ed.booktitle "booktitle" output.check
  2189.       format.bvolume output
  2190.       format.number.series output
  2191.       format.pages output
  2192. #if !NAMED_REFS
  2193.       address empty$
  2194.     { organization publisher new.sentence.checkb
  2195.       organization output
  2196.       publisher output
  2197.       format.date "year" output.check
  2198.     }
  2199.     { address output.nonnull
  2200.       format.date "year" output.check
  2201.       new.sentence
  2202.       organization output
  2203.       publisher output
  2204.     }
  2205.       if$
  2206. #else NAMED_REFS
  2207.       address output                    % for apalike
  2208.       new.sentence                    % there's no year
  2209.       organization output                % here so things
  2210.       publisher output                    % are simpler
  2211. #endif NAMED_REFS
  2212.     }
  2213.     { format.incoll.inproc.crossref output.nonnull
  2214.       format.pages output
  2215.     }
  2216.   if$
  2217.   new.block
  2218.   note output
  2219.   fin.entry
  2220. }
  2221.  
  2222. % The conference function is included for Scribe compatibility.
  2223.  
  2224. FUNCTION {conference} { inproceedings }
  2225.  
  2226. % A manual is technical documentation.
  2227. %    Required: title
  2228. %    Optional: author, organization, address, edition, month, year, note
  2229.  
  2230. FUNCTION {manual}
  2231. { output.bibitem
  2232. #if !NAMED_REFS
  2233.   author empty$
  2234.     { organization empty$
  2235.     'skip$
  2236.     { organization output.nonnull
  2237.       address output
  2238.     }
  2239.       if$
  2240.     }
  2241.     { format.authors output.nonnull }
  2242.   if$
  2243.   new.block
  2244.   format.btitle "title" output.check
  2245.   author empty$
  2246.     { organization empty$
  2247.     { address new.block.checka
  2248.       address output
  2249.     }
  2250.     'skip$
  2251.       if$
  2252.     }
  2253.     { organization address new.block.checkb
  2254.       organization output
  2255.       address output
  2256.     }
  2257.   if$
  2258.   format.edition output
  2259.   format.date output
  2260. #else NAMED_REFS
  2261.   format.authors output
  2262.   author format.key output                % special for
  2263.   output.year.check                    % apalike
  2264.   new.block
  2265.   format.btitle "title" output.check
  2266.   organization address new.block.checkb
  2267.   organization output
  2268.   address output
  2269.   format.edition output
  2270. #endif NAMED_REFS
  2271.   new.block
  2272.   note output
  2273.   fin.entry
  2274. }
  2275.  
  2276. % A mastersthesis is a Master's thesis.
  2277. %    Required: author, title, school, year
  2278. %    Optional: type, address, month, note
  2279.  
  2280. FUNCTION {mastersthesis}
  2281. { output.bibitem
  2282.   format.authors "author" output.check
  2283. #if NAMED_REFS
  2284.   author format.key output                % special for
  2285.   output.year.check                    % apalike
  2286. #endif NAMED_REFS
  2287.   new.block
  2288.   format.title "title" output.check
  2289.   new.block
  2290.   "Master's thesis" format.thesis.type output.nonnull
  2291.   school "school" output.check
  2292.   address output
  2293. #if !NAMED_REFS
  2294.   format.date "year" output.check
  2295. #endif !NAMED_REFS
  2296.   new.block
  2297.   note output
  2298.   fin.entry
  2299. }
  2300.  
  2301. % A misc is something that doesn't fit elsewhere.
  2302. %    Required: at least one of the `optional' fields
  2303. %    Optional: author, title, howpublished, month, year, note
  2304.  
  2305. FUNCTION {misc}
  2306. { output.bibitem
  2307.   format.authors output
  2308. #if !NAMED_REFS
  2309.   title howpublished new.block.checkb
  2310.   format.title output
  2311.   howpublished new.block.checka
  2312.   howpublished output
  2313.   format.date output
  2314. #else NAMED_REFS
  2315.   author format.key output                % special for
  2316.   output.year.check                    % apalike
  2317.   new.block
  2318.   format.title output
  2319.   new.block
  2320.   howpublished output
  2321. #endif NAMED_REFS
  2322.   new.block
  2323.   note output
  2324.   fin.entry
  2325. #if !NAMED_REFS
  2326.   empty.misc.check
  2327. #endif
  2328. }
  2329.  
  2330. % A phdthesis is like a mastersthesis.
  2331. %    Required: author, title, school, year
  2332. %    Optional: type, address, month, note
  2333.  
  2334. FUNCTION {phdthesis}
  2335. { output.bibitem
  2336.   format.authors "author" output.check
  2337. #if NAMED_REFS
  2338.   author format.key output                % special for
  2339.   output.year.check                    % apalike
  2340. #endif NAMED_REFS
  2341.   new.block
  2342.   format.btitle "title" output.check
  2343.   new.block
  2344.   "PhD thesis" format.thesis.type output.nonnull
  2345.   school "school" output.check
  2346.   address output
  2347. #if !NAMED_REFS
  2348.   format.date "year" output.check
  2349. #endif !NAMED_REFS
  2350.   new.block
  2351.   note output
  2352.   fin.entry
  2353. }
  2354.  
  2355. % A proceedings is a conference proceedings.
  2356. % If there is an organization but no editor field, the organization will
  2357. % appear as the first optional field (we try to make the first block nonempty);
  2358. % if there's no address field, the month (& year) will appear just before note.
  2359. %    Required: title, year
  2360. %    Optional: editor, volume or number, series, address, month,
  2361. %            organization, publisher, note
  2362.  
  2363. FUNCTION {proceedings}
  2364. { output.bibitem
  2365. #if !NAMED_REFS
  2366.   editor empty$
  2367.     { organization output }
  2368.     { format.editors output.nonnull }
  2369.   if$
  2370. #else NAMED_REFS
  2371.   format.editors output
  2372.   editor format.key output                % special for
  2373.   output.year.check                    % apalike
  2374. #endif NAMED_REFS
  2375.   new.block
  2376.   format.btitle "title" output.check
  2377.   format.bvolume output
  2378.   format.number.series output
  2379. #if !NAMED_REFS
  2380.   address empty$
  2381.     { editor empty$
  2382.     { publisher new.sentence.checka }
  2383.     { organization publisher new.sentence.checkb
  2384.       organization output
  2385.     }
  2386.       if$
  2387.       publisher output
  2388.       format.date "year" output.check
  2389.     }
  2390.     { address output.nonnull
  2391.       format.date "year" output.check
  2392.       new.sentence
  2393.       editor empty$
  2394.     'skip$
  2395.     { organization output }
  2396.       if$
  2397.       publisher output
  2398.     }
  2399.   if$
  2400. #else NAMED_REFS
  2401.   address output                % for apalike
  2402.   new.sentence                    % we always output
  2403.   organization output                % a nonempty organization
  2404.   publisher output                % here
  2405. #endif NAMED_REFS
  2406.   new.block
  2407.   note output
  2408.   fin.entry
  2409. }
  2410.  
  2411. % A techreport is a technical report.
  2412. %    Required: author, title, institution, year
  2413. %    Optional: type, number, address, month, note
  2414.  
  2415. FUNCTION {techreport}
  2416. { output.bibitem
  2417.   format.authors "author" output.check
  2418. #if NAMED_REFS
  2419.   author format.key output                % special for
  2420.   output.year.check                    % apalike
  2421. #endif NAMED_REFS
  2422.   new.block
  2423.   format.title "title" output.check
  2424.   new.block
  2425.   format.tr.number output.nonnull
  2426.   institution "institution" output.check
  2427.   address output
  2428. #if !NAMED_REFS
  2429.   format.date "year" output.check
  2430. #endif !NAMED_REFS
  2431.   new.block
  2432.   note output
  2433.   fin.entry
  2434. }
  2435.  
  2436. % An unpublished is something that hasn't been published.
  2437. %    Required: author, title, note
  2438. %    Optional: month, year
  2439.  
  2440. FUNCTION {unpublished}
  2441. { output.bibitem
  2442.   format.authors "author" output.check
  2443. #if NAMED_REFS
  2444.   author format.key output                % special for
  2445.   output.year.check                    % apalike
  2446. #endif NAMED_REFS
  2447.   new.block
  2448.   format.title "title" output.check
  2449.   new.block
  2450.   note "note" output.check
  2451. #if !NAMED_REFS
  2452.   format.date output
  2453. #endif
  2454.   fin.entry
  2455. }
  2456.  
  2457. % We use entry type `misc' for an unknown type; BibTeX gives a warning.
  2458.  
  2459. FUNCTION {default.type} { misc }
  2460.  
  2461. % Here are macros for common things that may vary from style to style.
  2462. % Users are encouraged to use these macros.
  2463. %
  2464. % Months are either written out in full or abbreviated
  2465.  
  2466. #if MONTH_FULL
  2467.  
  2468. MACRO {jan} {"January"}
  2469.  
  2470. MACRO {feb} {"February"}
  2471.  
  2472. MACRO {mar} {"March"}
  2473.  
  2474. MACRO {apr} {"April"}
  2475.  
  2476. MACRO {may} {"May"}
  2477.  
  2478. MACRO {jun} {"June"}
  2479.  
  2480. MACRO {jul} {"July"}
  2481.  
  2482. MACRO {aug} {"August"}
  2483.  
  2484. MACRO {sep} {"September"}
  2485.  
  2486. MACRO {oct} {"October"}
  2487.  
  2488. MACRO {nov} {"November"}
  2489.  
  2490. MACRO {dec} {"December"}
  2491.  
  2492. #else !MONTH_FULL
  2493.  
  2494. MACRO {jan} {"Jan."}
  2495.  
  2496. MACRO {feb} {"Feb."}
  2497.  
  2498. MACRO {mar} {"Mar."}
  2499.  
  2500. MACRO {apr} {"Apr."}
  2501.  
  2502. MACRO {may} {"May"}
  2503.  
  2504. MACRO {jun} {"June"}
  2505.  
  2506. MACRO {jul} {"July"}
  2507.  
  2508. MACRO {aug} {"Aug."}
  2509.  
  2510. MACRO {sep} {"Sept."}
  2511.  
  2512. MACRO {oct} {"Oct."}
  2513.  
  2514. MACRO {nov} {"Nov."}
  2515.  
  2516. MACRO {dec} {"Dec."}
  2517.  
  2518. #endif MONTH_FULL
  2519.  
  2520. % Journals are either written out in full or abbreviated;
  2521. % the abbreviations are like those found in ACM publications.
  2522. %
  2523. % To get a completely different set of abbreviations, it may be best to make
  2524. % a separate .bib file with nothing but those abbreviations; users could then
  2525. % include that file name as the first argument to the \bibliography command
  2526.  
  2527. #if JOUR_FULL
  2528.  
  2529. MACRO {acmcs} {"ACM Computing Surveys"}
  2530.  
  2531. MACRO {acta} {"Acta Informatica"}
  2532.  
  2533. MACRO {cacm} {"Communications of the ACM"}
  2534.  
  2535. MACRO {ibmjrd} {"IBM Journal of Research and Development"}
  2536.  
  2537. MACRO {ibmsj} {"IBM Systems Journal"}
  2538.  
  2539. MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
  2540.  
  2541. MACRO {ieeetc} {"IEEE Transactions on Computers"}
  2542.  
  2543. MACRO {ieeetcad}
  2544.  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
  2545.  
  2546. MACRO {ipl} {"Information Processing Letters"}
  2547.  
  2548. MACRO {jacm} {"Journal of the ACM"}
  2549.  
  2550. MACRO {jcss} {"Journal of Computer and System Sciences"}
  2551.  
  2552. MACRO {scp} {"Science of Computer Programming"}
  2553.  
  2554. MACRO {sicomp} {"SIAM Journal on Computing"}
  2555.  
  2556. MACRO {tocs} {"ACM Transactions on Computer Systems"}
  2557.  
  2558. MACRO {tods} {"ACM Transactions on Database Systems"}
  2559.  
  2560. MACRO {tog} {"ACM Transactions on Graphics"}
  2561.  
  2562. MACRO {toms} {"ACM Transactions on Mathematical Software"}
  2563.  
  2564. MACRO {toois} {"ACM Transactions on Office Information Systems"}
  2565.  
  2566. MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
  2567.  
  2568. MACRO {tcs} {"Theoretical Computer Science"}
  2569.  
  2570. #else !JOUR_FULL
  2571.  
  2572. MACRO {acmcs} {"ACM Comput. Surv."}
  2573.  
  2574. MACRO {acta} {"Acta Inf."}
  2575.  
  2576. MACRO {cacm} {"Commun. ACM"}
  2577.  
  2578. MACRO {ibmjrd} {"IBM J. Res. Dev."}
  2579.  
  2580. MACRO {ibmsj} {"IBM Syst.~J."}
  2581.  
  2582. MACRO {ieeese} {"IEEE Trans. Softw. Eng."}
  2583.  
  2584. MACRO {ieeetc} {"IEEE Trans. Comput."}
  2585.  
  2586. MACRO {ieeetcad}
  2587.  {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}
  2588.  
  2589. MACRO {ipl} {"Inf. Process. Lett."}
  2590.  
  2591. MACRO {jacm} {"J.~ACM"}
  2592.  
  2593. MACRO {jcss} {"J.~Comput. Syst. Sci."}
  2594.  
  2595. MACRO {scp} {"Sci. Comput. Programming"}
  2596.  
  2597. MACRO {sicomp} {"SIAM J. Comput."}
  2598.  
  2599. MACRO {tocs} {"ACM Trans. Comput. Syst."}
  2600.  
  2601. MACRO {tods} {"ACM Trans. Database Syst."}
  2602.  
  2603. MACRO {tog} {"ACM Trans. Gr."}
  2604.  
  2605. MACRO {toms} {"ACM Trans. Math. Softw."}
  2606.  
  2607. MACRO {toois} {"ACM Trans. Office Inf. Syst."}
  2608.  
  2609. MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}
  2610.  
  2611. MACRO {tcs} {"Theoretical Comput. Sci."}
  2612.  
  2613. #if PHYSICS_JOUR
  2614. #include "phyjfull.btx"
  2615. #endif PHYSICS_JOUR
  2616.  
  2617. #endif JOUR_FULL
  2618.  
  2619. % Now we read in the .BIB entries.
  2620.  
  2621. READ
  2622.  
  2623. % The sortify function converts to lower case after purify$ing; it's
  2624. % used in sorting and in computing alphabetic labels after sorting
  2625. %
  2626. % The chop.word(w,len,s) function returns either s or, if the first len
  2627. % letters of s equals w (this comparison is done in the third line of the
  2628. % function's definition), it returns that part of s after w.
  2629.  
  2630. #if SORTED
  2631.  
  2632. FUNCTION {sortify}
  2633. { purify$
  2634.   "l" change.case$
  2635. }
  2636.  
  2637. INTEGERS { len }
  2638.  
  2639. FUNCTION {chop.word}
  2640. { 's :=
  2641.   'len :=
  2642.   s #1 len substring$ =
  2643.     { s len #1 + global.max$ substring$ }
  2644.     's
  2645.   if$
  2646. }
  2647.  
  2648. #else !SORTED
  2649. #if LAB_ALPH
  2650.  
  2651. % We need the chop.word stuff for the dubious unsorted-list-with-labels case.
  2652.  
  2653. INTEGERS { len }
  2654.  
  2655. FUNCTION {chop.word}
  2656. { 's :=
  2657.   'len :=
  2658.   s #1 len substring$ =
  2659.     { s len #1 + global.max$ substring$ }
  2660.     's
  2661.   if$
  2662. }
  2663.  
  2664. #endif LAB_ALPH
  2665. #endif SORTED
  2666.  
  2667. % This long comment applies only to alphabetic labels
  2668. %
  2669. % The format.lab.names function makes a short label by using the initials of
  2670. % the von and Last parts of the names (but if there are more than four names,
  2671. % (i.e., people) it truncates after three and adds a superscripted "+";
  2672. % it also adds such a "+" if the last of multiple authors is "others").
  2673. % If there is only one name, and its von and Last parts combined have just
  2674. % a single name-token ("Knuth" has a single token, "Brinch Hansen" has two),
  2675. % we take the first three letters of the last name.  The boolean
  2676. % et.al.char.used tells whether we've used a superscripted "+", so that we
  2677. % know whether to include a LaTeX macro for it.
  2678. %
  2679. % format.lab.names(s) ==
  2680. %  BEGIN
  2681. %    numnames := num.names$(s)
  2682. %    if numnames > 1 then
  2683. %        if numnames > 4 then
  2684. %        namesleft := 3
  2685. %        else
  2686. %        namesleft := numnames
  2687. %        nameptr := 1
  2688. %        nameresult := ""
  2689. %        while namesleft > 0
  2690. %          do
  2691. %        if (name_ptr = numnames) and
  2692. %             format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
  2693. %           then nameresult := nameresult * "{\etalchar{+}}"
  2694. %            et.al.char.used := true
  2695. %           else nameresult := nameresult *
  2696. %                format.name$(s, nameptr, "{v{}}{l{}}")
  2697. %        nameptr := nameptr + 1
  2698. %        namesleft := namesleft - 1
  2699. %          od
  2700. %        if numnames > 4 then
  2701. %        nameresult := nameresult * "{\etalchar{+}}"
  2702. %        et.al.char.used := true
  2703. %    else
  2704. %        t := format.name$(s, 1, "{v{}}{l{}}")
  2705. %        if text.length$(t) < 2 then    % there's just one name-token
  2706. %        nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
  2707. %        else
  2708. %        nameresult := t
  2709. %        fi
  2710. %    fi
  2711. %    return nameresult
  2712. %  END
  2713. %
  2714. % Exactly what fields we look at in constructing the primary part of the label
  2715. % depends on the entry type; this selectivity (as opposed to, say, always
  2716. % looking at author, then editor, then key) helps ensure that "ignored" fields,
  2717. % as described in the LaTeX book, really are ignored.  Note that MISC is part
  2718. % of the deepest `else' clause in the nested part of calc.label; thus, any
  2719. % unrecognized entry type in the database is handled correctly.
  2720. %
  2721. % There is one auxiliary function for each of the four different sequences of
  2722. % fields we use.  The first of these functions looks at the author field, and
  2723. % then, if necessary, the key field.  The other three functions, which might
  2724. % look at two fields and the key field, are similar, except that the key field
  2725. % takes precedence over the organization field (for labels---not for sorting).
  2726. %
  2727. % The calc.label function calculates the preliminary label of an entry, which
  2728. % is formed by taking three letters of information from the author or editor or
  2729. % key or organization field (depending on the entry type and on what's empty,
  2730. % but ignoring a leading "The " in the organization), and appending the last
  2731. % two characters (digits) of the year. It is an error if the appropriate fields
  2732. % among author, editor, organization, and key are missing, and we use
  2733. % the first three letters of the cite$ in desperation when this happens.
  2734. % The resulting label has the year part, but not the name part, purify$ed
  2735. % (purify$ing the year allows some sorting shenanigans by the user).
  2736. %
  2737. % This function also calculates the version of the label to be used in sorting.
  2738. %
  2739. % The final label may need a trailing 'a', 'b', etc., to distinguish it from
  2740. % otherwise identical labels, but we can't calculated those "extra.label"s
  2741. % until after sorting.
  2742. %
  2743. % calc.label ==
  2744. %  BEGIN
  2745. %    if type$ = "book" or "inbook" then
  2746. %        author.editor.key.label
  2747. %    else if type$ = "proceedings" then
  2748. %        editor.key.organization.label
  2749. %    else if type$ = "manual" then
  2750. %        author.key.organization.label
  2751. %    else
  2752. %        author.key.label
  2753. %    fi fi fi
  2754. %    label := label * substring$(purify$(field.or.null(year)), -1, 2)
  2755. %        % assuming we will also sort, we calculate a sort.label
  2756. %    sort.label := sortify(label), but use the last four, not two, digits
  2757. %  END
  2758.  
  2759. #if LAB_ALPH
  2760.  
  2761. #if !NAMED_REFS
  2762. INTEGERS { et.al.char.used }
  2763.  
  2764. FUNCTION {initialize.et.al.char.used}
  2765. { #0 'et.al.char.used :=
  2766. }
  2767.  
  2768. EXECUTE {initialize.et.al.char.used}
  2769. #endif !NAMED_REFS
  2770.  
  2771. #if !NAMED_REFS
  2772. FUNCTION {format.lab.names}
  2773. #if !RMP_LABELS
  2774. { 's :=
  2775.   s num.names$ 'numnames :=
  2776.   numnames #1 >
  2777.     { numnames #4 >
  2778.     { #3 'namesleft := }
  2779.     { numnames 'namesleft := }
  2780.       if$
  2781.       #1 'nameptr :=
  2782.       ""
  2783.     { namesleft #0 > }
  2784.     { nameptr numnames =
  2785.         { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  2786.         { "{\etalchar{+}}" *
  2787.           #1 'et.al.char.used :=
  2788.         }
  2789.         { s nameptr "{v{}}{l{}}" format.name$ * }
  2790.           if$
  2791.         }
  2792.         { s nameptr "{v{}}{l{}}" format.name$ * }
  2793.       if$
  2794.       nameptr #1 + 'nameptr :=
  2795.       namesleft #1 - 'namesleft :=
  2796.     }
  2797.       while$
  2798.       numnames #4 >
  2799.     { "{\etalchar{+}}" *
  2800.       #1 'et.al.char.used :=
  2801.     }
  2802.     'skip$
  2803.       if$
  2804.     }
  2805.     { s #1 "{v{}}{l{}}" format.name$
  2806.       duplicate$ text.length$ #2 <
  2807.     { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
  2808.     'skip$
  2809.       if$
  2810.     }
  2811.   if$
  2812. }
  2813. #else RMP_LABELS
  2814. { 's :=
  2815.   s num.names$ 'numnames :=
  2816.   numnames #1 >
  2817.     { numnames #2 >
  2818. #if !CSC_NAMES
  2819. #if !ETAL_EMPH
  2820.        { s #1 "{vv }{ll}" format.name$ " et~al." * }
  2821. #else ETAL_EMPH
  2822.        { s #1 "{vv }{ll}" format.name$ " {\em et~al.}" * }
  2823. #endif ETAL_EMPH
  2824.        { s #1 "{vv }{ll}" format.name$
  2825. #else CSC_NAMES
  2826. #if !ETAL_EMPH
  2827.        { s #1 "{vv }{ll}" format.name$ caps " et~al." * }
  2828. #else ETAL_EMPH
  2829.        { s #1 "{vv }{ll}" format.name$ caps " {\em et~al.}" * }
  2830. #endif ETAL_EMPH
  2831.        { s #1 "{vv }{ll}" format.name$ caps
  2832. #endif CSC_NAMES
  2833.          s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  2834. #if !ETAL_EMPH
  2835.             { " et~al." * }
  2836. #else ETAL_EMPH
  2837.             { " {\em et~al.}" * }
  2838. #endif ETAL_EMPH
  2839. #if !CSC_NAMES
  2840.             { " and " * s #2 "{vv }{ll}" format.name$ * }
  2841. #else CSC_NAMES
  2842.             { " and " * s #2 "{vv }{ll}" format.name$ caps * }
  2843. #endif CSC_NAMES
  2844.          if$
  2845.        }
  2846.       if$
  2847.     }
  2848. #if !CSC_NAMES
  2849.     { s #1 "{vv }{ll}" format.name$ }
  2850. #else CSC_NAMES
  2851.     { s #1 "{vv }{ll}" format.name$ caps }
  2852. #endif
  2853.   if$
  2854. }
  2855. #endif
  2856. #else NAMED_REFS
  2857. %            There are three apalike cases: one person (Jones),
  2858. %            two (Jones and de~Bruijn), and more (Jones et~al.).
  2859. %            This function is much like format.crossref.editors.
  2860. %
  2861. FUNCTION {format.lab.names}
  2862. { 's :=
  2863. #if !CSC_NAMES
  2864.   s #1 "{vv~}{ll}" format.name$
  2865. #else CSC_NAMES
  2866.   s #1 "{vv~}{ll}" format.name$ caps
  2867. #endif CSC_NAMES
  2868.   s num.names$ duplicate$
  2869.   #2 >
  2870. #if !ETAL_EMPH
  2871.     { pop$ " et~al." * }
  2872. #else ETAL_EMPH
  2873.     { pop$ " {\em et~al.}" * }
  2874. #endif ETAL_EMPH
  2875.     { #2 <
  2876.     'skip$
  2877.     { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  2878. #if !ETAL_EMPH
  2879.         { " et~al." * }
  2880. #else ETAL_EMPH
  2881.         { " {\em et~al.}" * }
  2882. #endif ETAL_EMPH
  2883. #if !CSC_NAMES
  2884.         { " and " * s #2 "{vv~}{ll}" format.name$ * }
  2885. #else CSC_NAMES
  2886.         { " and " * s #2 "{vv~}{ll}" format.name$ caps * }
  2887. #endif
  2888.       if$
  2889.     }
  2890.       if$
  2891.     }
  2892.   if$
  2893. }
  2894. #endif NAMED_REFS
  2895.  
  2896. FUNCTION {author.key.label}
  2897. { author empty$
  2898.     { key empty$
  2899. #if SORTED
  2900.     { cite$ #1 #3 substring$ }
  2901. #else !SORTED        % need warning here because we won't give it later
  2902.     { "for label, need author or key in " cite$ * warning$
  2903.       cite$ #1 #3 substring$
  2904.     }
  2905. #endif SORTED
  2906. #if !NAMED_REFS
  2907.     { key #3 text.prefix$ }
  2908. #else NAMED_REFS
  2909.     'key                    % apalike uses the whole key
  2910. #endif NAMED_REFS
  2911.       if$
  2912.     }
  2913.     { author format.lab.names }
  2914.   if$
  2915. }
  2916.  
  2917. FUNCTION {author.editor.key.label}
  2918. { author empty$
  2919.     { editor empty$
  2920.     { key empty$
  2921. #if SORTED
  2922.         { cite$ #1 #3 substring$ }
  2923. #else !SORTED        % need warning here because we won't give it later
  2924.         { "for label, need author, editor, or key in " cite$ * warning$
  2925.           cite$ #1 #3 substring$
  2926.         }
  2927. #endif SORTED
  2928. #if !NAMED_REFS
  2929.         { key #3 text.prefix$ }
  2930. #else NAMED_REFS
  2931.         'key                % apalike uses the whole key
  2932. #endif NAMED_REFS
  2933.       if$
  2934.     }
  2935.     { editor format.lab.names }
  2936.       if$
  2937.     }
  2938.     { author format.lab.names }
  2939.   if$
  2940. }
  2941.  
  2942. #if !NAMED_REFS
  2943. FUNCTION {author.key.organization.label}
  2944. { author empty$
  2945.     { key empty$
  2946.     { organization empty$
  2947. #if SORTED
  2948.         { cite$ #1 #3 substring$ }
  2949. #else !SORTED        % need warning here because we won't give it later
  2950.         { "for label, need author, key, or organization in " cite$ *
  2951.                                 warning$
  2952.           cite$ #1 #3 substring$
  2953.         }
  2954. #endif SORTED
  2955. #if !RMP_LABELS
  2956.         { "The " #4 organization chop.word #3 text.prefix$ }
  2957. #else RMP_LABELS
  2958.         { "The " #4 organization chop.word #9 text.prefix$ }
  2959. #endif
  2960.       if$
  2961.     }
  2962.     { key #3 text.prefix$ }
  2963.       if$
  2964.     }
  2965.     { author format.lab.names }
  2966.   if$
  2967. }
  2968.  
  2969. FUNCTION {editor.key.organization.label}
  2970. { editor empty$
  2971.     { key empty$
  2972.     { organization empty$
  2973. #if SORTED
  2974.         { cite$ #1 #3 substring$ }
  2975. #else !SORTED        % need warning here because we won't give it later
  2976.         { "for label, need editor, key, or organization in " cite$ *
  2977.                                 warning$
  2978.           cite$ #1 #3 substring$
  2979.         }
  2980. #endif SORTED
  2981. #if !RMP_LABELS
  2982.         { "The " #4 organization chop.word #3 text.prefix$ }
  2983. #else RMP_LABELS
  2984.         { "The " #4 organization chop.word #9 text.prefix$ }
  2985. #endif
  2986.       if$
  2987.     }
  2988.     { key #3 text.prefix$ }
  2989.       if$
  2990.     }
  2991.     { editor format.lab.names }
  2992.   if$
  2993. }
  2994. #else NAMED_REFS
  2995. FUNCTION {editor.key.label}
  2996. { editor empty$
  2997.     { key empty$
  2998.     { cite$ #1 #3 substring$ }
  2999.     'key            % apalike uses the whole key, no organization
  3000.       if$
  3001.     }
  3002.     { editor format.lab.names }
  3003.   if$
  3004. }
  3005. #endif NAMED_REFS
  3006.  
  3007. FUNCTION {calc.label}
  3008. #if !KEY_CITE
  3009. { type$ "book" =
  3010.   type$ "inbook" =
  3011.   or
  3012.     'author.editor.key.label
  3013.     { type$ "proceedings" =
  3014. #if !NAMED_REFS
  3015.     'editor.key.organization.label
  3016.     { type$ "manual" =
  3017.         'author.key.organization.label
  3018.         'author.key.label
  3019.       if$
  3020.     }
  3021. #else NAMED_REFS
  3022.     'editor.key.label            % apalike ignores organization
  3023.     'author.key.label            % for labeling and sorting
  3024. #endif NAMED_REFS
  3025.       if$
  3026.     }
  3027.   if$
  3028. #if !NAMED_REFS
  3029.   duplicate$
  3030. #if !RMP_LABELS
  3031.   year field.or.null purify$ #-1 #2 substring$
  3032. #else RMP_LABELS
  3033.   " " * year field.or.null purify$ #-1 #4 substring$
  3034. #endif
  3035.   *
  3036.   'label :=
  3037.   year field.or.null purify$ #-1 #4 substring$
  3038.   *
  3039.   sortify 'sort.label :=
  3040. #else NAMED_REFS
  3041.   ", "                            % these three lines are
  3042.   *                            % for apalike, which
  3043.   year field.or.null purify$ #-1 #4 substring$        % uses all four digits
  3044.   *
  3045.   'label :=
  3046. #endif NAMED_REFS
  3047. }
  3048. #else KEY_CITE
  3049. { cite$ 'label :=
  3050. label sortify 'sort.label :=
  3051. }
  3052. #endif
  3053.  
  3054. % It doesn't seem like a particularly good idea to use an order-of-citation
  3055. % reference list when using alphabetic labels, but we need to have a
  3056. % special pass to calculate labels when this happens.
  3057.  
  3058. #if !SORTED
  3059.  
  3060. ITERATE {calc.label}
  3061.  
  3062. #endif !SORTED
  3063.  
  3064. #endif LAB_ALPH
  3065.  
  3066. % When sorting, we compute the sortkey by executing "presort" on each entry.
  3067. % The presort key contains a number of "sortify"ed strings, concatenated
  3068. % with multiple blanks between them.  This makes things like "brinch  per"
  3069. % come before "brinch hansen  per".
  3070. %
  3071. % The fields used here are: the sort.label for alphabetic labels (as set by
  3072. % calc.label), followed by the author names (or editor names or organization
  3073. % (with a leading "The " removed) or key field, depending on entry type and on
  3074. % what's empty), followed by year, followed by the first bit of the title
  3075. % (chopping off a leading "The ", "A ", or "An ").
  3076. % Names are formatted: Von Last First Junior.
  3077. % The names within a part will be separated by a single blank
  3078. % (such as "brinch hansen"), two will separate the name parts themselves
  3079. % (except the von and last), three will separate the names,
  3080. % four will separate the names from year (and from label, if alphabetic),
  3081. % and four will separate year from title.
  3082. %
  3083. % The sort.format.names function takes an argument that should be in
  3084. % BibTeX name format, and returns a string containing "   "-separated
  3085. % names in the format described above.  The function is almost the same
  3086. % as format.names.
  3087.  
  3088. #if SORTED
  3089.  
  3090. FUNCTION {sort.format.names}
  3091. { 's :=
  3092.   #1 'nameptr :=
  3093.   ""
  3094.   s num.names$ 'numnames :=
  3095.   numnames 'namesleft :=
  3096.     { namesleft #0 > }
  3097.     { nameptr #1 >
  3098.     { "   " * }
  3099.     'skip$
  3100. #if NAME_FULL
  3101.       if$
  3102.       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
  3103. #else
  3104.       if$                        % apalike uses initials
  3105.       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't := % <= here
  3106. #endif NAME_FULL
  3107.       nameptr numnames = t "others" = and
  3108.     { "et al" * }
  3109.     { t sortify * }
  3110.       if$
  3111.       nameptr #1 + 'nameptr :=
  3112.       namesleft #1 - 'namesleft :=
  3113.     }
  3114.   while$
  3115. }
  3116.  
  3117. % The sort.format.title function returns the argument,
  3118. % but first any leading "A "'s, "An "'s, or "The "'s are removed.
  3119. % The chop.word function uses s, so we need another string variable, t
  3120.  
  3121. FUNCTION {sort.format.title}
  3122. { 't :=
  3123.   "A " #2
  3124.     "An " #3
  3125.       "The " #4 t chop.word
  3126.     chop.word
  3127.   chop.word
  3128.   sortify
  3129.   #1 global.max$ substring$
  3130. }
  3131.  
  3132. % The auxiliary functions here, for the presort function, are analogous to
  3133. % the ones for calc.label; the same comments apply, except that the
  3134. % organization field takes precedence here over the key field.  For sorting
  3135. % purposes, we still remove a leading "The " from the organization field.
  3136.  
  3137. FUNCTION {author.sort}
  3138. { author empty$
  3139.     { key empty$
  3140.     { "to sort, need author or key in " cite$ * warning$
  3141.       ""
  3142.     }
  3143.     { key sortify }
  3144.       if$
  3145.     }
  3146.     { author sort.format.names }
  3147.   if$
  3148. }
  3149.  
  3150. FUNCTION {author.editor.sort}
  3151. { author empty$
  3152.     { editor empty$
  3153.     { key empty$
  3154.         { "to sort, need author, editor, or key in " cite$ * warning$
  3155.           ""
  3156.         }
  3157.         { key sortify }
  3158.       if$
  3159.     }
  3160.     { editor sort.format.names }
  3161.       if$
  3162.     }
  3163.     { author sort.format.names }
  3164.   if$
  3165. }
  3166.  
  3167. #if !NAMED_REFS
  3168. FUNCTION {author.organization.sort}
  3169. { author empty$
  3170.     { organization empty$
  3171.     { key empty$
  3172.         { "to sort, need author, organization, or key in " cite$ * warning$
  3173.           ""
  3174.         }
  3175.         { key sortify }
  3176.       if$
  3177.     }
  3178.     { "The " #4 organization chop.word sortify }
  3179.       if$
  3180.     }
  3181.     { author sort.format.names }
  3182.   if$
  3183. }
  3184.  
  3185. FUNCTION {editor.organization.sort}
  3186. { editor empty$
  3187.     { organization empty$
  3188.     { key empty$
  3189.         { "to sort, need editor, organization, or key in " cite$ * warning$
  3190.           ""
  3191.         }
  3192.         { key sortify }
  3193.       if$
  3194.     }
  3195.     { "The " #4 organization chop.word sortify }
  3196.       if$
  3197.     }
  3198.     { editor sort.format.names }
  3199.   if$
  3200. }
  3201. #else NAMED_REFS
  3202. FUNCTION {editor.sort}
  3203. { editor empty$
  3204.     { key empty$
  3205.     { "to sort, need editor or key in " cite$ * warning$
  3206.       ""
  3207.     }
  3208.     { key sortify }
  3209.       if$
  3210.     }
  3211.     { editor sort.format.names }
  3212.   if$
  3213. }
  3214. #endif NAMED_REFS
  3215.  
  3216. #if !NAMED_REFS
  3217. % There is a limit, entry.max$, on the length of an entry string variable
  3218. % (which is what its sort.key$ is), so we take at most that many characters
  3219. % of the constructed key, and hope there aren't many references that match
  3220. % to that many characters!
  3221.  
  3222. FUNCTION {presort}
  3223. #if LAB_ALPH
  3224. { calc.label
  3225.   sort.label
  3226.   "    "
  3227.   *
  3228.   type$ "book" =
  3229. #else !LAB_ALPH
  3230. { type$ "book" =
  3231. #endif LAB_ALPH
  3232.   type$ "inbook" =
  3233.   or
  3234.     'author.editor.sort
  3235.     { type$ "proceedings" =
  3236.     'editor.organization.sort
  3237.     { type$ "manual" =
  3238.         'author.organization.sort
  3239.         'author.sort
  3240.       if$
  3241.     }
  3242.       if$
  3243.     }
  3244.   if$
  3245. #if LAB_ALPH
  3246.   *
  3247. #endif LAB_ALPH
  3248.   "    "
  3249.   *
  3250.   year field.or.null sortify
  3251.   *
  3252.   "    "
  3253.   *
  3254.   title field.or.null
  3255.   sort.format.title
  3256.   *
  3257.   #1 entry.max$ substring$
  3258.   'sort.key$ :=
  3259. }
  3260. #else NAMED_REFS
  3261. %            apalike uses two sorting passes; the first one sets the
  3262. %            labels so that the `a's, `b's, etc. can be computed;
  3263. %            the second pass puts the references in "correct" order.
  3264. %            The presort function is for the first pass. It computes
  3265. %            label, sort.label, and title, and then concatenates.
  3266. FUNCTION {presort}
  3267. { calc.label
  3268.   label sortify
  3269.   "    "
  3270.   *
  3271.   type$ "book" =
  3272.   type$ "inbook" =
  3273.   or
  3274.     'author.editor.sort
  3275.     { type$ "proceedings" =
  3276.     'editor.sort
  3277.     'author.sort
  3278.       if$
  3279.     }
  3280.   if$
  3281.   #1 entry.max$ substring$    % for
  3282.   'sort.label :=        % apalike
  3283.   sort.label            % style
  3284.   *
  3285.   "    "
  3286.   *
  3287.   title field.or.null
  3288.   sort.format.title
  3289.   *
  3290.   #1 entry.max$ substring$
  3291.   'sort.key$ :=
  3292. }
  3293. #endif NAMED_REFS
  3294.  
  3295. ITERATE {presort}
  3296.  
  3297. % And now we can sort
  3298.  
  3299. #if !NAMED_REFS
  3300. SORT
  3301. #else NAMED_REFS
  3302. SORT        % by label, sort.label, title---for final label calculation
  3303. #endif
  3304.  
  3305. #endif SORTED
  3306.  
  3307. % This long comment applies only to alphabetic labels, when sorted
  3308. %
  3309. % Now comes the final computation for alphabetic labels, putting in the 'a's
  3310. % and 'b's and so forth if required.  This involves two passes: a forward
  3311. % pass to put in the 'b's, 'c's and so on, and a backwards pass
  3312. % to put in the 'a's (we don't want to put in 'a's unless we know there
  3313. % are 'b's).
  3314. % We have to keep track of the longest (in width$ terms) label, for use
  3315. % by the "thebibliography" environment.
  3316. %
  3317. % VAR: longest.label, last.sort.label, next.extra: string
  3318. %      longest.label.width, last.extra.num: integer
  3319. %
  3320. % initialize.longest.label ==
  3321. %  BEGIN
  3322. %    longest.label := ""
  3323. %    last.sort.label := int.to.chr$(0)
  3324. %    next.extra := ""
  3325. %    longest.label.width := 0
  3326. %    last.extra.num := 0
  3327. %  END
  3328. %
  3329. % forward.pass ==
  3330. %  BEGIN
  3331. %    if last.sort.label = sort.label then
  3332. %        last.extra.num := last.extra.num + 1
  3333. %        extra.label := int.to.chr$(last.extra.num)
  3334. %    else
  3335. %        last.extra.num := chr.to.int$("a")
  3336. %        extra.label := ""
  3337. %        last.sort.label := sort.label
  3338. %    fi
  3339. %  END
  3340. %
  3341. % reverse.pass ==
  3342. %  BEGIN
  3343. %    if next.extra = "b" then
  3344. %        extra.label := "a"
  3345. %    fi
  3346. %    label := label * extra.label
  3347. %    if width$(label) > longest.label.width then
  3348. %        longest.label := label
  3349. %        longest.label.width := width$(label)
  3350. %    fi
  3351. %    next.extra := extra.label
  3352. %  END
  3353.  
  3354. #if LAB_ALPH
  3355.  
  3356. #if SORTED
  3357.  
  3358. #if !NAMED_REFS
  3359. STRINGS { longest.label last.sort.label next.extra }
  3360.  
  3361. INTEGERS { longest.label.width last.extra.num }
  3362.  
  3363. FUNCTION {initialize.longest.label}
  3364. { "" 'longest.label :=
  3365.   #0 int.to.chr$ 'last.sort.label :=
  3366.   "" 'next.extra :=
  3367.   #0 'longest.label.width :=
  3368.   #0 'last.extra.num :=
  3369. }
  3370.  
  3371. FUNCTION {forward.pass}
  3372. { last.sort.label sort.label =
  3373.     { last.extra.num #1 + 'last.extra.num :=
  3374.       last.extra.num int.to.chr$ 'extra.label :=
  3375.     }
  3376.     { "a" chr.to.int$ 'last.extra.num :=
  3377.       "" 'extra.label :=
  3378.       sort.label 'last.sort.label :=
  3379.     }
  3380.   if$
  3381. }
  3382. #else NAMED_REFS
  3383. STRINGS { last.label next.extra }    % apalike labels are only for the text;
  3384.  
  3385. INTEGERS { last.extra.num }        % there are none in the bibliography
  3386.  
  3387. FUNCTION {initialize.extra.label.stuff}    % and hence there is no `longest.label'
  3388. { #0 int.to.chr$ 'last.label :=
  3389.   "" 'next.extra :=
  3390.   #0 'last.extra.num :=
  3391. }
  3392.  
  3393. FUNCTION {forward.pass}
  3394. { last.label label =
  3395.     { last.extra.num #1 + 'last.extra.num :=
  3396.       last.extra.num int.to.chr$ 'extra.label :=
  3397.     }
  3398.     { "a" chr.to.int$ 'last.extra.num :=
  3399.       "" 'extra.label :=
  3400.       label 'last.label :=
  3401.     }
  3402.   if$
  3403. }
  3404. #endif NAMED_REFS
  3405.  
  3406. FUNCTION {reverse.pass}
  3407. { next.extra "b" =
  3408.     { "a" 'extra.label := }
  3409.     'skip$
  3410.   if$
  3411.   label extra.label * 'label :=
  3412. #if !NAMED_REFS
  3413.   label width$ longest.label.width >
  3414.     { label 'longest.label :=
  3415.       label width$ 'longest.label.width :=
  3416.     }
  3417.     'skip$
  3418.   if$
  3419. #endif !NAMED_REFS
  3420.   extra.label 'next.extra :=
  3421. }
  3422.  
  3423. #if !NAMED_REFS
  3424. EXECUTE {initialize.longest.label}
  3425. #else NAMED_REFS
  3426. EXECUTE {initialize.extra.label.stuff}
  3427. #endif NAMED_REFS
  3428.  
  3429. ITERATE {forward.pass}
  3430.  
  3431. REVERSE {reverse.pass}
  3432.  
  3433. #if NAMED_REFS
  3434. %                Now that the label is right we sort for real,
  3435. %                on sort.label then year then title.  This is
  3436. %                for the second sorting pass.
  3437. FUNCTION {bib.sort.order}
  3438. { sort.label
  3439.   "    "
  3440.   *
  3441.   year field.or.null sortify
  3442.   *
  3443.   "    "
  3444.   *
  3445.   title field.or.null
  3446.   sort.format.title
  3447.   *
  3448.   #1 entry.max$ substring$
  3449.   'sort.key$ :=
  3450. }
  3451.  
  3452. ITERATE {bib.sort.order}
  3453.  
  3454. SORT        % by sort.label, year, title---giving final bibliography order
  3455. #endif NAMED_REFS
  3456. #else !SORTED
  3457.  
  3458. % It still doesn't seem like a good idea to use an order-of-citation
  3459. % reference list when using alphabetic labels, but when this happens we
  3460. % must compute the longest label
  3461.  
  3462. STRINGS { longest.label }
  3463.  
  3464. INTEGERS { longest.label.width }
  3465.  
  3466. FUNCTION {initialize.longest.label}
  3467. { "" 'longest.label :=
  3468.   #0 'longest.label.width :=
  3469. }
  3470.  
  3471. FUNCTION {longest.label.pass}
  3472. { label width$ longest.label.width >
  3473.     { label 'longest.label :=
  3474.       label width$ 'longest.label.width :=
  3475.     }
  3476.     'skip$
  3477.   if$
  3478. }
  3479.  
  3480. EXECUTE {initialize.longest.label}
  3481.  
  3482. ITERATE {longest.label.pass}
  3483.  
  3484. #endif SORTED
  3485.  
  3486. #else !LAB_ALPH
  3487.  
  3488. % Now comes the computation for numeric labels.
  3489. % We use either the sorted order or original order.
  3490. % We still have to keep track of the longest (in width$ terms) label, for use
  3491. % by the "thebibliography" environment.
  3492.  
  3493. STRINGS { longest.label }
  3494.  
  3495. INTEGERS { number.label longest.label.width }
  3496.  
  3497. FUNCTION {initialize.longest.label}
  3498. { "" 'longest.label :=
  3499.   #1 'number.label :=
  3500.   #0 'longest.label.width :=
  3501. }
  3502.  
  3503. FUNCTION {longest.label.pass}
  3504. { number.label int.to.str$ 'label :=
  3505.   number.label #1 + 'number.label :=
  3506.   label width$ longest.label.width >
  3507.     { label 'longest.label :=
  3508.       label width$ 'longest.label.width :=
  3509.     }
  3510.     'skip$
  3511.   if$
  3512. }
  3513.  
  3514. EXECUTE {initialize.longest.label}
  3515.  
  3516. ITERATE {longest.label.pass}
  3517.  
  3518. #endif LAB_ALPH
  3519.  
  3520. % Now we're ready to start writing the .BBL file.
  3521. % We begin, if necessary, with a LaTeX macro for unnamed names in an alphabetic
  3522. % label; next comes stuff from the `preamble' command in the database files.
  3523. % Then we give an incantation containing the command
  3524. %     \begin{thebibliography}{...}
  3525. % where the `...' is the longest label.
  3526. %
  3527. % We also call init.state.consts, for use by the output routines.
  3528.  
  3529. FUNCTION {begin.bib}
  3530. #if !NAMED_REFS
  3531. #if LAB_ALPH
  3532. { et.al.char.used
  3533.     { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
  3534.     'skip$
  3535.   if$
  3536.   preamble$ empty$
  3537. #else !LAB_ALPH
  3538. { preamble$ empty$
  3539. #endif LAB_ALPH
  3540.     'skip$
  3541.     { preamble$ write$ newline$ }
  3542.   if$
  3543.   "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
  3544. }
  3545. #else NAMED_REFS
  3546. { preamble$ empty$                % no \etalchar in apalike
  3547.     'skip$
  3548.     { preamble$ write$ newline$ }
  3549.   if$
  3550.   "\begin{thebibliography}{}" write$ newline$        % no labels in apalike
  3551. }
  3552. #endif NAMED_REFS
  3553.  
  3554. EXECUTE {begin.bib}
  3555.  
  3556. EXECUTE {init.state.consts}
  3557.  
  3558. % Now we produce the output for all the entries
  3559.  
  3560. ITERATE {call.type$}
  3561.  
  3562. % Finally, we finish up by writing the `\end{thebibliography}' command.
  3563.  
  3564. FUNCTION {end.bib}
  3565. { newline$
  3566.   "\end{thebibliography}" write$ newline$
  3567. }
  3568.  
  3569. EXECUTE {end.bib}
  3570.